[BUG][CORE] Use intersection of required fields across anyOf/oneOf members#23670
Open
winrid wants to merge 3 commits intoOpenAPITools:masterfrom
Open
[BUG][CORE] Use intersection of required fields across anyOf/oneOf members#23670winrid wants to merge 3 commits intoOpenAPITools:masterfrom
winrid wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
…mbers
The merged composed model from anyOf/oneOf added every member's required
fields to the resulting `required` set. Per OAS / JSON Schema semantics,
a value is only guaranteed present if EVERY member of an anyOf/oneOf
requires it, so the merged set should be the intersection.
Example:
response:
anyOf:
- $ref: '#/components/schemas/VoteResponse' # required: [status, voteId]
- $ref: '#/components/schemas/APIError' # required: [status, reason, code]
Previously: status, voteId, reason, code all marked required.
Now: only status is required (the only field present in both).
allOf semantics are unchanged (still union).
Affects every generator that consumes CodegenModel.required for non-null
types or constructor signatures (Swift, Kotlin, Java POJOs, Dart, etc.).
Sample regeneration may flip previously-required fields to optional in
generated code where this pattern is in use; that is the intended
behavior.
Test: anyOfRequiredFieldsIntersectionTest in Swift6ClientCodegenModelTest
covers the contract via swift6_anyof_required.yaml (chosen because
swift6 is one of the affected generators; the change itself lives in
DefaultCodegen and applies everywhere).
Closes OpenAPITools#23667
Cascade from the union->intersection change in DefaultCodegen. Fields previously marked required across all members of an anyOf/oneOf are now optional in the merged composed model. Touches Go, Kotlin, R, C#, Java, JavaScript, PowerShell, Rust, TypeScript, Python, Dart-dio, Terraform samples that contain anyOf composed schemas with overlapping required fields.
… anyOf required-intersection
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.
Closes #23667.
The merged composed model from
anyOf/oneOfadds every member'srequiredfields to the resultingrequiredset. Per OAS / JSON Schema semantics, a value is only guaranteed present if EVERY member of ananyOf/oneOfrequires it, so the merged set should be the intersection.Previously:
status, voteId, reason, codeall marked required. Now: onlystatusis required (the only field present in both).allOfsemantics are unchanged (still union).Affects
Every generator that consumes
CodegenModel.requiredfor non-null types or constructor signatures (Swift, Kotlin, Java POJOs, Dart, etc.). Sample regeneration may flip previously-required fields to optional in generated code where this pattern is in use; that is the intended behavior.Test
anyOfRequiredFieldsIntersectionTestinSwift6ClientCodegenModelTestcovers the contract againstswift6_anyof_required.yaml(chosen because swift6 is one of the affected generators; the change itself lives inDefaultCodegenand applies everywhere). All 164DefaultCodegenTestcases and 39 swift6 codegen tests pass.Sample regeneration
The source change is intentionally landed without a multi-language sample regen since this affects ~every generator and the diff would be unmanageable. Maintainers may want to follow up with a samples regeneration pass; happy to spin out a follow-up PR if that's preferred.
PR checklist
master(5.x.x) (patches will be cascaded frommasterto other branches by the maintainers)cc @wing328 @jimschubert