Repository navigation
[rust] fix: discriminated-union variants drop every child-specific field #24897
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
Merged
wing328
merged 9 commits into
OpenAPITools:master
from
wiebren:fix/rust-discriminated-union-child-fields
Oct 5, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1619b60
[rust] fix: discriminated-union variants keep the child's own fields
wiebren 9939a94
[rust] rework: remove the discriminator property from mapped children
wiebren a887544
[rust] fix: keep the child's discriminator, tolerate the consumed ser…
wiebren 881bd64
[rust] fix: tagged unions read and write the tag through the child
wiebren 1c0da30
Revert "[rust] fix: tagged unions read and write the tag through the …
wiebren e9ad7d4
[rust] fix: enum-typed discriminators and self-mapped unions compile
wiebren 7a39f1f
[rust] fix: enum-typed discriminators keep the inline variants
wiebren 37c3372
test: [rust] pin the derived serde tag on the unions
wiebren daa9c0d
Merge remote-tracking branch 'origin/master' into fix/rust-discrimina…
wiebren 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
Some comments aren't visible on the classic Files Changed page.
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
143 changes: 143 additions & 0 deletions
143
modules/openapi-generator/src/test/resources/3_0/rust/discriminated-union.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,143 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: discriminated union | ||
| version: 1.0.0 | ||
| paths: | ||
| /errors: | ||
| get: | ||
| operationId: getError | ||
| responses: | ||
| '200': | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ApiError' | ||
| components: | ||
| schemas: | ||
| ApiError: | ||
| type: object | ||
| required: | ||
| - type | ||
| - message | ||
| properties: | ||
| type: | ||
| type: string | ||
| message: | ||
| type: string | ||
| discriminator: | ||
| propertyName: type | ||
| mapping: | ||
| ObjectExists: '#/components/schemas/ObjectExists' | ||
| ValidationError: '#/components/schemas/ValidationError' | ||
| ObjectExists: | ||
| allOf: | ||
| - $ref: '#/components/schemas/ApiError' | ||
| - type: object | ||
| required: | ||
| - identifier | ||
| properties: | ||
| identifier: | ||
| type: string | ||
| objectType: | ||
| type: string | ||
| ValidationError: | ||
| allOf: | ||
| - $ref: '#/components/schemas/ApiError' | ||
| - type: object | ||
| properties: | ||
| field: | ||
| type: string | ||
| # nullable discriminator: String::is_empty would not compile against it | ||
| NullableTagged: | ||
| type: object | ||
| required: | ||
| - kind | ||
| properties: | ||
| kind: | ||
| type: string | ||
| nullable: true | ||
| label: | ||
| type: string | ||
| discriminator: | ||
| propertyName: kind | ||
| mapping: | ||
| Alpha: '#/components/schemas/Alpha' | ||
| Alpha: | ||
| allOf: | ||
| - $ref: '#/components/schemas/NullableTagged' | ||
| - type: object | ||
| properties: | ||
| alphaOnly: | ||
| type: string | ||
| # enum-typed discriminators, inline and $ref: the union keeps the inline variants | ||
| Pet: | ||
| type: object | ||
| required: | ||
| - petType | ||
| properties: | ||
| petType: | ||
| type: string | ||
| enum: [Cat, Dog] | ||
| discriminator: | ||
| propertyName: petType | ||
| mapping: | ||
| Cat: '#/components/schemas/Cat' | ||
| Dog: '#/components/schemas/Dog' | ||
| Cat: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: object | ||
| properties: | ||
| lives: | ||
| type: integer | ||
| Dog: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| - type: object | ||
| properties: | ||
| bark: | ||
| type: boolean | ||
| ShapeKind: | ||
| type: string | ||
| enum: [circle] | ||
| Shape: | ||
| type: object | ||
| required: | ||
| - kind | ||
| properties: | ||
| kind: | ||
| $ref: '#/components/schemas/ShapeKind' | ||
| discriminator: | ||
| propertyName: kind | ||
| mapping: | ||
| circle: '#/components/schemas/Circle' | ||
| Circle: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Shape' | ||
| - type: object | ||
| properties: | ||
| radius: | ||
| type: number | ||
| # the mapping names the base itself: no struct to wrap, so the union keeps the inline variants | ||
| Creature: | ||
| type: object | ||
| required: | ||
| - kind | ||
| properties: | ||
| kind: | ||
| type: string | ||
| name: | ||
| type: string | ||
| discriminator: | ||
| propertyName: kind | ||
| mapping: | ||
| Creature: '#/components/schemas/Creature' | ||
| Bird: '#/components/schemas/Bird' | ||
| Bird: | ||
| allOf: | ||
| - $ref: '#/components/schemas/Creature' | ||
| - type: object | ||
| properties: | ||
| wingspan: | ||
| type: number |
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.
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.