-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[Kotlin-client] fix kotlin code client generator for oneOf with allOf #24163
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
bykakashka
wants to merge
3
commits into
OpenAPITools:master
Choose a base branch
from
bykakashka:fix/kotlin_client_allOf-oneOf
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.
+276
−7
Open
Changes from all commits
Commits
Show all changes
3 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
69 changes: 69 additions & 0 deletions
69
.../openapi-generator/src/test/resources/3_1/polymorphism-allof-and-oneof-discriminator.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,69 @@ | ||
| # Test spec for allOf/oneOf inheritance with discriminator. | ||
| # Verifies that child properties (e.g. huntingSkill, packSize) are not leaked | ||
| # into the parent interface or sibling models. | ||
| # Based on OAS 3.1 example: https://spec.openapis.org/oas/v3.2.0.html#models-with-polymorphism-support-and-a-discriminator-object | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Polymorphism with allOf, oneOf and discriminator | ||
| version: "1.0" | ||
| paths: {} | ||
| components: | ||
| schemas: | ||
| Pet: | ||
| description: A pet | ||
| type: object | ||
| discriminator: | ||
| propertyName: petType | ||
| mapping: | ||
| cat: '#/components/schemas/Cat' | ||
| dog: '#/components/schemas/Dog' | ||
| properties: | ||
| name: | ||
| type: string | ||
| required: | ||
| - name | ||
| - petType | ||
| oneOf: | ||
| - $ref: '#/components/schemas/Cat' | ||
| - $ref: '#/components/schemas/Dog' | ||
| Cat: | ||
| description: A pet cat | ||
| type: object | ||
| allOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| properties: | ||
| petType: | ||
| const: 'cat' | ||
| huntingSkill: | ||
| type: string | ||
| description: The measured skill for hunting | ||
| enum: | ||
| - clueless | ||
| - lazy | ||
| - adventurous | ||
| - aggressive | ||
| required: | ||
| - huntingSkill | ||
| Dog: | ||
| description: A pet dog | ||
| type: object | ||
| allOf: | ||
| - $ref: '#/components/schemas/Pet' | ||
| properties: | ||
| petType: | ||
| const: 'dog' | ||
| packSize: | ||
| type: integer | ||
| format: int32 | ||
| description: the size of the pack the dog is from | ||
| default: 0 | ||
| minimum: 0 | ||
| required: | ||
| - petType | ||
| - packSize | ||
| House: | ||
| description: A house | ||
| type: object | ||
| properties: | ||
| pet: | ||
| $ref: '#/components/schemas/Pet' |
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.
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.
P2: Setting
skipOneOfPropertyMergeInParent = trueunconditionally in the KotlinClientCodegen constructor affects all oneOf/anyOf schemas, not just the oneOf+allOf case described in the PR. InDefaultCodegen.addProperties(), this flag prevents merging oneOf AND anyOf child properties into parent models globally. Since KotlinClientCodegen only supports oneOf/anyOf wrappers forjvm-retrofit2withgson/kotlinx_serialization, and the default isjvm-okhttp4withmoshi, plain oneOf/anyOf schemas under default or unsupported configurations may lose child properties with no wrapper fallback. Consider scoping this flag to the specific oneOf+allOf/discriminator case or to library/serialization combinations that provide wrapper support.Prompt for AI agents
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.
The bug affects all serialization libraries equally. Without the fix, moshi, gson, and kotlinx_serialization all produce identical broken output — fat parent interfaces with leaked child properties and sibling contamination.
Plain oneOf without discriminator is NOT affected. These schemas generate a data class wrapper (not an interface), and addProperties() merging is correct — the wrapper IS supposed to contain all variant properties as a union type. Tested and confirmed.
Plain allOf without discriminator is NOT affected. Standard inheritance works identically with and without the fix.
Added 16 new parameterized tests covering all 4 patterns (plain oneOf, oneOf+discriminator, plain allOf, allOf+discriminator) × all 4 serialization libraries (jackson, moshi, gson, kotlinx_serialization) — all pass. The flag is safe to set unconditionally at the KotlinClientCodegen level.