rewrite $ref in top-level oneOf/anyOf branches during variant generation#35
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances the schema preprocessing logic to handle top-level oneOf and anyOf branches, ensuring that external references are correctly rewritten to their corresponding request or update variants. This change is reflected in the updated FulfillmentDestination models. Feedback suggests that the current implementation is too narrow and should be expanded to cover the entire variant object, including allOf and items fields, to prevent base models from being incorrectly referenced in generated request variants.
|
Hi @xiaoxuanz-hub, I opened #52 to address the separate array-root request variant issue tracked in #37. The two PRs are complementary: #35 fixes request-variant I intentionally kept #52 scoped and excluded the whole-variant |
Description
Fix
_create_single_variantinpreprocess_schemas.pyto rewrite external$reflinks in top-leveloneOf/anyOfbranches when generating request variant schemas.Previously,
rewrite_refs_to_variantswas only called on$refs found insideproperties. Schemas that define union types via top-leveloneOf/anyOf(with noproperties), such asfulfillment_destination.json, had their$refs left pointing to the base response schemas instead of the corresponding request variant files. This caused generated wrapper models likeFulfillmentDestinationCreateRequestto incorrectly referenceShippingDestination(response, requiresid) instead ofShippingDestinationCreateRequest(request,idoptional).The fix adds a post-processing step after property handling to also rewrite
$refs in the variant's top-leveloneOf/anyOfbranches.Affected generated models:
FulfillmentDestinationCreateRequest— now wrapsShippingDestinationCreateRequest|RetailLocationCreateRequestFulfillmentDestinationUpdateRequest— now wrapsShippingDestinationUpdateRequest|RetailLocationUpdateRequestCategory (Required)
Please select one or more categories that apply to this change.
ucp-schematool (resolver, linter, validator). (Requires Maintainer approval)Related Issues
Fixes #34
Checklist
Screenshots / Logs (if applicable)