[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
The kotlin-server generator produces `typealias Foo = Any` for `oneOf` schemas with discriminators instead of a sealed interface, which causes compile errors when subtypes try to extend it. The fix mirrors PR OpenAPITools#23574 (kotlin-spring): set `useOneOfInterfaces = true` in the constructor so the codegen pipeline emits the correct model metadata, and add an `oneof_interface.mustache` template that renders a sealed interface with Jackson annotations. Fixes the regression introduced in 7.20.0 where kotlin-server specs using `oneOf` + `discriminator` + `allOf` subtype patterns stopped compiling.
- Fix data_class.mustache: only emit constructor args when x-parent-ctor-args is present (interface parents don't have constructors) - Fix KotlinServerCodegen: skip x-parent-ctor-args when useOneOfInterfaces is true - Update jaxrs-spec model.mustache to route x-is-one-of-interface through oneof_interface - Update existing tests to expect sealed interface instead of sealed class for oneOf - Fix test to use TestUtils.parseSpec() instead of unavailable OpenAPIParser - Regenerate affected samples
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. Restores correct polymorphism and fixes compile errors forallOfsubtypes.useOneOfInterfaces = trueinKotlinServerCodegen.oneof_interface.mustacheto render a sealed interface with Jackson@JsonTypeInfo/@JsonSubTypes.x-is-one-of-interfacein bothmodel.mustacheandlibraries/jaxrs-spec/model.mustache.data_class.mustache); skip when generating interfaces.TestUtils.parseSpec; regenerate affected samples.Written for commit f2d564f. Summary will update on new commits. Review in cubic