-
Notifications
You must be signed in to change notification settings - Fork 321
Fix circular references in JSON Schema discriminated unions with polymorphic-models-strategy #9056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…minated unions to avoid circular references
commit: |
|
All changed packages have been documented.
Show changes
|
|
/azp run typespec - pr tools |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
You can try these changes here
|
timotheeguerin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- from offline talk update the doc to specify what this fully does
| @@ -0,0 +1,7 @@ | |||
| --- | |||
| changeKind: fix | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| changeKind: fix | |
| changeKind: internal |
can be internal as the original change wasn't released in regular version
Fix circular references in JSON Schema discriminated unions with polymorphic-models-strategy
Problem
When using
polymorphic-models-strategy: "oneOf"(or"anyOf") with discriminated unions, the JSON Schema emitter generates circular references that cause validation errors:Pet) emitsoneOf: [Cat, Dog]Cat,Dog) emitallOf: [{ $ref: "Pet.json" }]Pet → Cat → Pet(via oneOf and allOf)JSON Schema validators reject these circular references, making it impossible to validate payloads against the discriminated union schemas.
Solution
When a model extends a base model that uses the discriminated union strategy:
allOfto reference the base model (avoiding circular references)oneOf/anyOfwithout propertiesExample
Before (circular reference):
After (no circular reference):