-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Fix allOf with $ref to discriminator-less oneOf flattening all variant properties
#23498
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
Open
jasperpatterson
wants to merge
2
commits into
OpenAPITools:master
Choose a base branch
from
jasperpatterson:fix-allof-oneof-ref-flattening
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
63 changes: 63 additions & 0 deletions
63
modules/openapi-generator/src/test/resources/3_0/allOf_oneOf_noDiscriminator.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| openapi: 3.0.2 | ||
| info: | ||
| title: allOf with oneOf (no discriminator) test | ||
| version: 1.0.0 | ||
| paths: | ||
| /parent: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ParentC' | ||
| components: | ||
| schemas: | ||
| ParentC: | ||
| allOf: | ||
| - type: object | ||
| required: [type] | ||
| properties: | ||
| type: | ||
| type: string | ||
| - $ref: "#/components/schemas/Child" | ||
|
|
||
| Child: | ||
| oneOf: | ||
| - $ref: "#/components/schemas/ChildX" | ||
| - $ref: "#/components/schemas/ChildY" | ||
| - $ref: "#/components/schemas/ChildZ" | ||
|
|
||
| ChildX: | ||
| type: object | ||
| required: [kind, sharedField, xOnlyField] | ||
| properties: | ||
| kind: | ||
| type: string | ||
| sharedField: | ||
| type: string | ||
| xOnlyField: | ||
| type: string | ||
|
|
||
| ChildY: | ||
| type: object | ||
| required: [kind, sharedField, yOnlyField] | ||
| properties: | ||
| kind: | ||
| type: string | ||
| sharedField: | ||
| type: string | ||
| yOnlyField: | ||
| type: string | ||
|
|
||
| ChildZ: | ||
| type: object | ||
| required: [kind, sharedField, zOnlyField] | ||
| properties: | ||
| kind: | ||
| type: string | ||
| sharedField: | ||
| type: string | ||
| zOnlyField: | ||
| type: integer |
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ public partial class ShapeOrNull : IValidatableObject | |
| /// Initializes a new instance of the <see cref="ShapeOrNull" /> class. | ||
| /// </summary> | ||
| /// <param name="triangle"></param> | ||
| public ShapeOrNull(Triangle triangle) | ||
| internal ShapeOrNull(Triangle triangle) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: ShapeOrNull no longer has any public constructor or factory; changing the union constructors to internal makes the public model non-instantiable for SDK consumers. Prompt for AI agents |
||
| { | ||
| Triangle = triangle; | ||
| OnCreated(); | ||
|
|
@@ -44,7 +44,7 @@ public ShapeOrNull(Triangle triangle) | |
| /// Initializes a new instance of the <see cref="ShapeOrNull" /> class. | ||
| /// </summary> | ||
| /// <param name="quadrilateral"></param> | ||
| public ShapeOrNull(Quadrilateral quadrilateral) | ||
| internal ShapeOrNull(Quadrilateral quadrilateral) | ||
| { | ||
| Quadrilateral = quadrilateral; | ||
| OnCreated(); | ||
|
|
@@ -117,8 +117,6 @@ public override ShapeOrNull Read(ref Utf8JsonReader utf8JsonReader, Type typeToC | |
|
|
||
| JsonTokenType startingTokenType = utf8JsonReader.TokenType; | ||
|
|
||
| Option<string?> shapeType = default; | ||
|
|
||
| Quadrilateral? quadrilateral = null; | ||
| Triangle? triangle = null; | ||
|
|
||
|
|
@@ -167,21 +165,12 @@ public override ShapeOrNull Read(ref Utf8JsonReader utf8JsonReader, Type typeToC | |
|
|
||
| switch (localVarJsonPropertyName) | ||
| { | ||
| case "shapeType": | ||
| shapeType = new Option<string?>(utf8JsonReader.GetString()!); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!shapeType.IsSet) | ||
| throw new ArgumentException("Property is required for class ShapeOrNull.", nameof(shapeType)); | ||
|
|
||
| if (shapeType.IsSet && shapeType.Value == null) | ||
| throw new ArgumentNullException(nameof(shapeType), "Property is not nullable for class ShapeOrNull."); | ||
|
|
||
| if (quadrilateral != null) | ||
| return new ShapeOrNull(quadrilateral); | ||
|
|
||
|
|
||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.