Skip to content

Commit 48b7c85

Browse files
author
Dennis Ameling
authored
[kotlin-server] Add polymorphism, oneOf and allOf support (#22610)
* [kotlin-server] Add polymorphism support * Fix CI triggers * Fix FILES * Fix samples and related triggers * Fix FILES * Add discriminator property to sealed class * Fix double nullability issue * Update samples
1 parent 3ecb490 commit 48b7c85

67 files changed

Lines changed: 1830 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/samples-kotlin-server-jdk17.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Samples Kotlin server (jdk17)
33
on:
44
push:
55
paths:
6+
- 'samples/server/others/kotlin-server/**'
67
- 'samples/server/petstore/kotlin-springboot-3*/**'
78
- 'samples/server/petstore/kotlin-server/**'
89
- 'samples/server/petstore/kotlin-server-modelMutable/**'
@@ -13,6 +14,7 @@ on:
1314
# - samples/server/petstore/kotlin-spring-default/**
1415
pull_request:
1516
paths:
17+
- 'samples/server/others/kotlin-server/**'
1618
- 'samples/server/petstore/kotlin-springboot-3*/**'
1719
- 'samples/server/petstore/kotlin-server/**'
1820
- 'samples/server/petstore/kotlin-server-modelMutable/**'
@@ -34,6 +36,10 @@ jobs:
3436
matrix:
3537
sample:
3638
# server
39+
- samples/server/others/kotlin-server/polymorphism-allof-and-discriminator
40+
- samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix
41+
- samples/server/others/kotlin-server/polymorphism-and-discriminator
42+
- samples/server/others/kotlin-server/polymorphism
3743
- samples/server/petstore/kotlin-server-required-and-nullable-properties
3844
- samples/server/petstore/kotlin-springboot-3
3945
- samples/server/petstore/kotlin-springboot-3-no-response-entity

.github/workflows/samples-kotlin-server-jdk21.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ name: Samples Kotlin server (jdk21)
33
on:
44
push:
55
paths:
6+
- 'samples/server/others/kotlin-server/**'
67
- 'samples/server/petstore/kotlin-server/**'
78
- 'samples/server/petstore/kotlin-server-required-and-nullable-properties/**'
89
pull_request:
910
paths:
11+
- 'samples/server/others/kotlin-server/**'
1012
- 'samples/server/petstore/kotlin-server/**'
1113
- 'samples/server/petstore/kotlin-server-required-and-nullable-properties/**'
1214

@@ -21,6 +23,10 @@ jobs:
2123
fail-fast: false
2224
matrix:
2325
sample:
26+
- samples/server/others/kotlin-server/polymorphism-allof-and-discriminator
27+
- samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix
28+
- samples/server/others/kotlin-server/polymorphism-and-discriminator
29+
- samples/server/others/kotlin-server/polymorphism
2430
- samples/server/petstore/kotlin-server/javalin-6
2531
- samples/server/petstore/kotlin-server/ktor
2632
- samples/server/petstore/kotlin-server/ktor2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: kotlin-server
2+
outputDir: samples/server/others/kotlin-server/polymorphism-allof-and-discriminator
3+
inputSpec: modules/openapi-generator/src/test/resources/3_1/polymorphism-allof-and-discriminator.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
5+
additionalProperties:
6+
artifactId: kotlin-server-polymorphism-allof-and-discriminator
7+
library: javalin6
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: kotlin-server
2+
outputDir: samples/server/others/kotlin-server/polymorphism-and-discriminator-disabled-jackson-fix
3+
inputSpec: modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
5+
additionalProperties:
6+
artifactId: kotlin-server-polymorphism-and-discriminator-disabled-jackson-fix
7+
library: javalin6
8+
# This is set to "true" by default, but we also want to test the case where it's set to false.
9+
# See KotlinServerCodegen.java for more details about this property.
10+
fixJacksonJsonTypeInfoInheritance: false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: kotlin-server
2+
outputDir: samples/server/others/kotlin-server/polymorphism-and-discriminator
3+
inputSpec: modules/openapi-generator/src/test/resources/3_1/polymorphism-and-discriminator.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
5+
additionalProperties:
6+
artifactId: kotlin-server-polymorphism-and-discriminator
7+
library: javalin6
8+
fixJacksonJsonTypeInfoInheritance: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: kotlin-server
2+
outputDir: samples/server/others/kotlin-server/polymorphism
3+
inputSpec: modules/openapi-generator/src/test/resources/3_1/polymorphism.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-server
5+
additionalProperties:
6+
artifactId: kotlin-server-polymorphism
7+
library: javalin6

docs/generators/kotlin-server.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3030
|featureHSTS|Avoid sending content if client already has same content, by checking ETag or LastModified properties.| |true|
3131
|featureMetrics|Enables metrics feature.| |true|
3232
|featureResources|Generates routes in a typed way, for both: constructing URLs and reading the parameters.| |true|
33+
|fixJacksonJsonTypeInfoInheritance|When true (default), ensures Jackson polymorphism works correctly by: (1) always setting visible=true on @JsonTypeInfo, and (2) adding the discriminator property to child models with appropriate default values. When false, visible is only set to true if all children already define the discriminator property.| |true|
3334
|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools|
3435
|interfaceOnly|Whether to generate only API interface stubs without the server files. This option is currently supported only when using jaxrs-spec library.| |false|
3536
|library|library template (sub-template)|<dl><dt>**ktor**</dt><dd>ktor framework</dd><dt>**ktor2**</dt><dd>ktor (2.x) framework</dd><dt>**jaxrs-spec**</dt><dd>JAX-RS spec only</dd><dt>**javalin5**</dt><dd>Javalin 5</dd><dt>**javalin6**</dt><dd>Javalin 6</dd></dl>|ktor|
@@ -262,11 +263,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
262263
| ---- | --------- | ---------- |
263264
|Simple|✓|OAS2,OAS3
264265
|Composite|✓|OAS2,OAS3
265-
|Polymorphism||OAS2,OAS3
266+
|Polymorphism||OAS2,OAS3
266267
|Union|✗|OAS3
267-
|allOf||OAS2,OAS3
268+
|allOf||OAS2,OAS3
268269
|anyOf|✗|OAS3
269-
|oneOf||OAS3
270+
|oneOf||OAS3
270271
|not|✗|OAS3
271272

272273
### Security Feature

0 commit comments

Comments
 (0)