You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2f13add
Browse filesBrowse the repository at this point in the historyBrowse files
[kotlin-spring] seal allOf discriminator parent interfaces by default (#23953)
A model with a discriminator is rendered as an interface. Because the
generator knows every subtype at generation time, that interface can be
sealed, which lets callers use exhaustive `when` matching and stops
external code from adding implementors that the discriminator mapping
does not know about.
Adds `useSealedDiscriminatorInterfaces` (default true). Set it to false
to restore the plain `interface` rendering, which is needed when the
generated interface is implemented from outside the generated package.
Also declares SchemaSupportFeature.allOf, which the generator supports
but did not advertise.
Claude-Session: https://claude.ai/code/session_01VBn7VWUxZL6mTUbg21xNjm
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/generators/kotlin-spring.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
74
74
|useFlowForArrayReturnType|Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.||true|
75
75
|useJackson3|Use Jackson 3 dependencies (tools.jackson package). Only available with `useSpringBoot4`. Defaults to true when `useSpringBoot4` is enabled.||false|
76
76
|useResponseEntity|Whether (when false) to return actual type (e.g. List<Fruit>) and handle non-happy path responses via exceptions flow or (when true) return entire ResponseEntity (e.g. ResponseEntity<List<Fruit>>). If disabled, method are annotated using a @ResponseStatus annotation, which has the status of the first response declared in the Api definition||true|
77
+
|useSealedDiscriminatorInterfaces|Generate sealed interfaces instead of plain interfaces for allOf discriminator parent models. When true (default), discriminator parents rendered as `sealed interface`, enabling exhaustive `when` matching and preventing external implementors (which cannot know all subtypes). Set to false to restore the legacy plain `interface` behavior, e.g. when you implement the generated interface from a module outside the generated package.||true|
77
78
|useSealedResponseInterfaces|Generate sealed interfaces for endpoint responses that all possible response types implement. Allows controllers to return any valid response type in a type-safe manner (e.g., sealed interface CreateUserResponse implemented by User, ConflictResponse, ErrorResponse)||false|
78
79
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot ≥ 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.||false|
79
80
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x. Enabling this option will also enable `useJakartaEe`.||false|
@@ -325,7 +326,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
@@ -262,7 +264,8 @@ public KotlinSpringServerCodegen() {
262
264
)
263
265
.includeSchemaSupportFeatures(
264
266
SchemaSupportFeature.Polymorphism,
265
-
SchemaSupportFeature.oneOf
267
+
SchemaSupportFeature.oneOf,
268
+
SchemaSupportFeature.allOf
266
269
)
267
270
.includeParameterFeatures(
268
271
ParameterFeature.Cookie
@@ -329,6 +332,13 @@ public KotlinSpringServerCodegen() {
329
332
addSwitch(USE_SEALED_RESPONSE_INTERFACES,
330
333
"Generate sealed interfaces for endpoint responses that all possible response types implement. Allows controllers to return any valid response type in a type-safe manner (e.g., sealed interface CreateUserResponse implemented by User, ConflictResponse, ErrorResponse)",
331
334
useSealedResponseInterfaces);
335
+
addSwitch(USE_SEALED_DISCRIMINATOR_INTERFACES,
336
+
"Generate sealed interfaces instead of plain interfaces for allOf discriminator parent models. " +
"`when` matching and preventing external implementors (which cannot know all subtypes). " +
339
+
"Set to false to restore the legacy plain `interface` behavior, e.g. when you implement " +
340
+
"the generated interface from a module outside the generated package.",
341
+
useSealedDiscriminatorInterfaces);
332
342
addOption(X_KOTLIN_IMPLEMENTS_SKIP, "A list of fully qualified interfaces that should NOT be implemented despite their presence in vendor extension `x-kotlin-implements`. Example: yaml `xKotlinImplementsSkip: [com.some.pack.WithPhotoUrls]` skips implementing the interface in any schema", "empty list");
333
343
addOption(X_KOTLIN_IMPLEMENTS_FIELDS_SKIP, "A list of fields per schema name that should NOT be created with `override` keyword despite their presence in vendor extension `x-kotlin-implements-fields` for the schema. Example: yaml `xKotlinImplementsFieldsSkip: Pet: [photoUrls]` skips `override` for `photoUrls` in schema `Pet`", "empty map");
334
344
addOption(SCHEMA_IMPLEMENTS, "A map of single interface or a list of interfaces per schema name that should be implemented (serves similar purpose as `x-kotlin-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)", "empty map");
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java
+88Lines changed: 88 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8105,4 +8105,92 @@ public void testMultiLevelAllOfWithEscapedPropertyNames() throws IOException {
Copy file name to clipboardExpand all lines: samples/server/petstore/kotlin-springboot-include-http-request-context-delegate/src/main/kotlin/org/openapitools/model/Pet.kt
Copy file name to clipboardExpand all lines: samples/server/petstore/kotlin-springboot-x-kotlin-implements/src/main/kotlin/org/openapitools/model/Pet.kt
0 commit comments