feat(models): modular domain structure and elimination of legacy postprocessors - #97
Open
gsmith85 wants to merge 4 commits into
Open
feat(models): modular domain structure and elimination of legacy postprocessors#97gsmith85 wants to merge 4 commits into
gsmith85 wants to merge 4 commits into
Conversation
added 4 commits
September 10, 2026 05:55
- Embed shopping.openapi.json (244 KB) exported from ucp-schema - Update generate_models.sh with native datamodel-codegen flags (--use-one-literal-as-default, --use-default) - Eliminate all brittle re.sub regex string replacements - Remove obsolete preprocess_schemas.py (-834 LOC) and prune legacy preprocessor tests (-974 LOC) - Maintain full test suite pass rate (122 tests passing) and ruff compliance - Resolves Universal-Commerce-Protocol/ucp#817
…penapi.json - Ensure generate_models.sh resolves version arguments (e.g. 2026-08-25) to embedded shopping.openapi.json - Format shopping.openapi.json with prettier to comply with pre-commit
…gacy postprocessors - Generate consolidated models directly from OpenAPI 3.1 specification (shopping.openapi.json) - Synthesize modular domain packages (shopping/, common/types/, profile.py, etc.) to preserve consumer ergonomics and backwards compatibility - Delete postprocess_models.py (-1,965 LOC) and 227 legacy zombie schema files (-15,530 LOC) - Replace legacy test_codegen_pipeline.py with comprehensive, unskipped unit tests (tests/test_models.py) verifying polymorphic deserialization, directional requests, and validation invariants - Net reduction: ~10,350 lines of code
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
Companion PR to Universal-Commerce-Protocol/ucp-schema#73 and Universal-Commerce-Protocol/ucp#817.
This PR transitions the Python SDK models to be generated directly from the canonical OpenAPI 3.1 specification (
shopping.openapi.json) emitted byucp-schema export-openapi. This change removes both the schema preprocessing script (preprocess_schemas.py) and the model postprocessing script (postprocess_models.py), replacing the legacy 227-file schema directory with a consolidated model engine and modular re-export packages.Overall diff: +11,280 lines, -21,663 lines (net reduction of 10,383 lines of code).
Why the Preprocessor and Postprocessor Were Removed Concurrently
While splitting the removal of
preprocess_schemas.pyandpostprocess_models.pyinto separate PRs was considered, the two tools were tightly coupled by design:postprocess_models.pywas implemented around AST traversal of individual per-schema files acrosssrc/ucp_sdk/models/schemas/{common,shopping}/. It looked for specific file paths (such astotals.pyandtime_interval.py) to inject custom@model_validatormethods.ValueConstraintandConstraintExpression). Generating separate files per schema withdatamodel-code-generatortriggers Pydantic v2 circular reference exceptions (PydanticUserError). Resolving these references reliably requires topological ordering within a consolidated module (models.py).postprocess_models.pycould not operate on the consolidatedmodels.pywithout a substantial rewrite of its AST parser, keeping it in an intermediate state would have required maintaining the 227 legacy files and running the postprocessor solely against unreferenced code.Consequently, removing both scripts together and introducing lightweight modular packages avoids maintaining an artificial intermediate state while aligning with the strategy to decouple wire DTOs from full JSON Schema semantic evaluation.
Key Changes
Elimination of Legacy Scripts and Files:
preprocess_schemas.py(-834 LOC): Schema composition, reference rewriting,$defshoisting, and polymorphic lowering are handled upstream byucp-schema.postprocess_models.py(-1,965 LOC): Manual AST modification and validator injection are eliminated.src/ucp_sdk/models/schemas/{common,shopping}/.Consolidated Topological Engine (
models.py):shopping.openapi.json(244 KB) intosrc/ucp_sdk/models/schemas/models.py.datamodel-code-generatorconfiguration (--use-one-literal-as-default,--use-type-alias,--use-default) with no regex post-filtering.Modular Domain Packages:
shopping/checkout.py,shopping/cart.py,shopping/types/fulfillment_destination.py,common/types/totals.py, etc.) that re-export classes frommodels.pywith explicit__all__.Updated Test Suite (
tests/test_models.py):tests/test_codegen_pipeline.py(which tested internal helpers of the deleted preprocessor) with unit tests intests/test_models.pythat directly validate the generated models:FulfillmentDestinationdynamically parsingShippingDestinationandLocationDestination).CheckoutCreateRequestomitting read-only server fields).Checkout,Cart, andOrder.Verification