Conversation
This was referenced Jun 5, 2026
rvlasveld
marked this pull request as draft
June 5, 2026 11:11
rvlasveld
commented
Jun 5, 2026
This comment was marked as outdated.
This comment was marked as outdated.
rvlasveld
marked this pull request as ready for review
June 5, 2026 12:35
Contributor
Author
|
@wing328, could you help get this reviewed? |
Member
|
@rvlasveld thanks for the PR can you please PM me via Slack to go through your PRs and get them merged? https://join.slack.com/t/openapi-generator/shared_invite/zt-36ucx4ybl-jYrN6euoYn6zxXNZdldoZA |
rvlasveld
force-pushed
the
fix/kotlin-spring-allof-discriminator-defaults
branch
from
September 20, 2026 13:58
549b8fc to
43abab4
Compare
Member
|
please resolve the merge conflicts when you've time. will try to review, test it before the upcoming stable release (due later this coming week) |
…r value A child of a discriminator parent already knows its own discriminating value, but the generated property was an ordinary required constructor parameter, so every caller had to pass it and could pass a wrong one. The discriminator property now gets a default value taken from the discriminator mapping, matching what the oneOf path already did. The oneOf-specific loop is generalised to every discriminator parent, so allOf parents are covered by the same code path. The value is the mapping key, which is not always the schema name: a spec mapping DOG -> Dog makes "DOG" the discriminating value. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VBn7VWUxZL6mTUbg21xNjm
rvlasveld
force-pushed
the
fix/kotlin-spring-allof-discriminator-defaults
branch
from
September 27, 2026 21:07
43abab4 to
2a85d55
Compare
This branch has not been deployed
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.
What
A child of a discriminator parent already knows its own discriminating value, but
kotlin-springgenerated that property as an ordinary required constructor parameter. Callers had to pass it on every construction, and nothing stopped them passing a wrong one:The discriminator property now carries a default taken from the discriminator mapping:
The
oneOfpath already did this. This PR generalises that loop to every discriminator parent, soallOfparents are handled by the same code rather than a parallel implementation.The emitted value is the mapping key, not the schema name
Worth highlighting, because it is easy to get wrong. Given:
the generated default is
"DOG", not"Dog". This falls out ofCodegenDiscriminator.MappedModelordering and the de-duplication inDefaultCodegen.createDiscriminator()— subtle enough that it is now pinned by a dedicated test (testAllOfDiscriminatorMappingKeyDiffersFromSchemaName), using the existingpetstore-with-fake-endpoints-for-testing-with-cookie.yamlspec which mapsDOG/CATontoDog/Cat.Behaviour change
The discriminator property gains a default value, so it becomes optional at the call site. This is source-compatible for existing callers that still pass it explicitly. Callers who passed a wrong value keep compiling — the default only changes what happens when the argument is omitted.
The rewritten loop is also no longer gated on
x-is-one-of-interface: it now runs for every model with a discriminator and a non-empty mapped-model set. In practice that widens coverage fromoneOftoallOf(the point of the PR) and toanyOf, which shares the same mapped-model machinery.Tests
KotlinSpringServerCodegenTest: 286 passing, 3 of them new (default from schema name, default from explicit mapping, mapping key ≠ schema name).Samples
Regenerated all
kotlin-springsample configs. Three samples change — notekotlin-springboot-request-cookieis included, which the earlier revision of this PR had missed:kotlin-springboot-x-kotlin-implements—Cat/Dogkotlin-springboot-include-http-request-context-delegate—Cat/Dogkotlin-springboot-request-cookie—Cat/Dog(shows= "DOG"/= "CAT")For maintainers
different regions of
KotlinSpringServerCodegen.javaand different sample files, so the onlyoverlap is a both-added resolution at the tail of
KotlinSpringServerCodegenTest.java.allOf-multilevelsample, whoseAnimalchildren are allOf discriminator children — so this PR now also givesDog,CatandBigDogtheirclassNamedefaults in that sample. This is the regeneration [kotlin-spring] fix multi-level allOf inheritance (fixes #18206) #23954 flagged asdue once this landed, not a new behaviour.
anyOfis now in scope as described above. It is untested here because nokotlin-springsample exercises ananyOfdiscriminator; happy to add one if you would rather have it covered explicitly.🤖 Generated with Claude Code
https://claude.ai/code/session_01VBn7VWUxZL6mTUbg21xNjm