refactor!: migrate totals.json from array to object schema - #684
Draft
gsmith85 wants to merge 2 commits into
Draft
refactor!: migrate totals.json from array to object schema#684gsmith85 wants to merge 2 commits into
gsmith85 wants to merge 2 commits into
Conversation
gsmith85
force-pushed
the
feat/refactor-totals-object-schema
branch
from
August 5, 2026 04:48
adb3773 to
0ee0023
Compare
gsmith85
force-pushed
the
feat/refactor-totals-object-schema
branch
from
August 5, 2026 04:53
0ee0023 to
051e2db
Compare
damaz91
reviewed
Aug 10, 2026
| "amount" | ||
| ], | ||
| "properties": { | ||
| "type": { |
Contributor
There was a problem hiding this comment.
probably we should also remove this, as type is now defined as the key in the totals dictionary?
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
While auditing downstream code generator workarounds during review of RFC #484, I identified that
source/schemas/shopping/types/totals.jsonuses a RootArray ("type": "array") schema which is responsible for much of the post processing logic our SDK generation requires.This PR refactors
totals.jsonfrom a top-level array into a top-level object ("type": "object") which will:*-sdkrepositories.totals.jsonschema with modern UCP schema design guidelines.Why RootArray Schemas Cause Generator Friction
Defining a resource as a RootArray (
"type": "array"at schema root) causes four specific failure modes in schema-driven toolchains:RootModelFriction): Generators cannot emit standard named classes (class Totals(BaseModel)). Instead, they emit anonymousRootModel/TypeAliasTypewrappers, breaking direct JSON serialization in web frameworks (e.g., FastAPI).totals.find(t => t.type === "subtotal")) instead of direct typed property access (totals.subtotal.amount).contains/minContainsrules entirely, forcing 180+ lines of AST post-processing in Python (postprocess_models.py#L170-L346) and 8 duplicated.superRefineZod callbacks in TypeScript (spec_generated.ts#L677-L700).display_orderhint) in future revisions without a breaking schema change.Developer Experience Comparison
Python SDK:
TypeScript SDK:
Conformance with UCP Schema Guidelines
The refactored
totals.jsonandtotal.jsonschemas directly conform to official UCP authoring standards:docs/documentation/schema-authoring.md#string-vocabularies-vs-enums("Prefer open string vocabularies with documented well-known values over closedenumarrays.")"enum": ["subtotal", "tax", ...]array fromtotals.json, preventing breaking changes when new total categories are added in future releases.docs/documentation/schema-authoring.md#open-enumerations("Avoid complex validation patterns... as they frequently confuse client-side code generators and make schemas difficult to read.")contains/allOf/if/thenconditional rules with standard object properties (required: ["subtotal", "total"]), eliminating generator confusion.docs/specification/overview.mdtotals.jsoninto 100% architectural parity with all other core UCP resources (cart,checkout,payment,fulfillment), which are uniformly modeled as top-level objects.Receipt Rendering & Itemization
display_orderstring array hint (["subtotal", "discount", "fulfillment", "tax", "total"]) preserves custom merchant receipt rendering order without requiring array schema hacks.linesarray intotal.json.additionalProperties: { "$ref": "total.json" }. This allows businesses and platform extensions to introduce shopping line items (gift_wrapping_fee,recycling_fee,bottle_deposit,tip,store_credit) without requiring a breaking schema revision or version bump.