[kotlin-server] Enable oneOf sealed interface generation - #23846
Open
mcuk-globalid wants to merge 2 commits into
Open
[kotlin-server] Enable oneOf sealed interface generation#23846mcuk-globalid wants to merge 2 commits into
mcuk-globalid wants to merge 2 commits into
Conversation
mcuk-globalid
force-pushed
the
fix/kotlin-server-oneOf-interface
branch
from
May 26, 2026 10:10
f2d564f to
875f200
Compare
Member
|
thanks for the pr cc @karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02) |
Member
|
please review the build failure when you've time |
added 2 commits
July 30, 2026 10:07
The kotlin-server generator produces `typealias Foo = Any` for oneOf schemas with discriminators instead of a proper type hierarchy. This causes compile errors when subtypes try to extend the parent type. Root cause: KotlinServerCodegen declares SchemaSupportFeature.oneOf but does not set useOneOfInterfaces = true, so the codegen pipeline never produces the x-is-one-of-interface vendor extension. Fix (mirrors OpenAPITools#23574 for kotlin-spring): - Set useOneOfInterfaces = true in KotlinServerCodegen constructor - Add oneof_interface.mustache template for sealed interface with Jackson annotations - Update model.mustache to route x-is-one-of-interface models to the new template - Update jaxrs-spec model.mustache for the same routing - Fix data_class.mustache: only emit constructor args when x-parent-ctor-args is present - Skip x-parent-ctor-args when useOneOfInterfaces is true (interfaces have no constructors) - Update existing tests to expect sealed interface instead of sealed class for oneOf - Regenerate affected samples
Only declare the discriminator on the oneOf sealed interface when the subtypes are actually rendered with 'override' (i.e. when fixJacksonJsonTypeInfoInheritance is enabled). Otherwise the subtypes failed to compile with "'petType' hides member of supertype 'Pet' and needs an 'override' modifier". Emit 'override' for inherited properties in the jaxrs-spec library templates, which hit the same error. Let oneOf members declare the sealed interface as a supertype via x-implements, so a discriminator-less oneOf no longer produces an empty interface that nothing implements.
mcuk-globalid
force-pushed
the
fix/kotlin-server-oneOf-interface
branch
from
July 30, 2026 08:51
875f200 to
9056b41
Compare
Author
|
@wing328 pushed update |
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.
Summary
The
kotlin-servergenerator producestypealias Foo = AnyforoneOfschemas with discriminators instead of a sealed interface. This causes compile errors when subtypes (generated viaallOf) try to extend the parent type.Reproducer: any OpenAPI 3.1.x spec with
oneOf+discriminator+allOfsubtype pattern (e.g.src/test/resources/3_1/polymorphism-and-discriminator.yaml) generates:instead of:
Subtypes then fail to compile because
Anyhas a constructor that cannot be delegated to.Root cause:
KotlinServerCodegendeclaresSchemaSupportFeature.oneOfandSchemaSupportFeature.Polymorphismbut does not setuseOneOfInterfaces = true, so the codegen pipeline never produces thex-is-one-of-interfacevendor extension. Themodel.mustachetemplate also lacks the routing to aoneof_interfacetemplate.Fix
Mirrors #23574 (kotlin-spring):
useOneOfInterfaces = trueinKotlinServerCodegenconstructoroneof_interface.mustachetemplate forkotlin-server(sealed interface with Jackson@JsonTypeInfo/@JsonSubTypesannotations)model.mustacheto routex-is-one-of-interfacemodels to the new templateRelated issues
🤖 Generated with Claude Code
Summary by cubic
Generate sealed interfaces for
oneOfschemas inkotlin-serverinstead oftypealias Any, fixing polymorphism and compile errors. Discriminators are declared on the interface only when subtypes override them, andoneOfmembers now implement the interface even without a discriminator.useOneOfInterfaces = trueinKotlinServerCodegen; addoneof_interface.mustacheand route viamodel.mustacheandlibraries/jaxrs-spec/model.mustache.fixJacksonJsonTypeInfoInheritancemakes subtypesoverrideit.oneOfmembers implement the sealed interface viax-implements, including discriminator-lessoneOf.x-parent-ctor-argsfor interfaces indata_class.mustache.libraries/jaxrs-specvar templates, emitoverridefor inherited properties; update tests and samples to expect sealed interfaces (notypealias).Written for commit 9056b41. Summary will update on new commits.