Skip to content

Commit 44a3be1

Browse files
authored
fix(kotlin-spring): add missing constructor parentheses for hashmap models (#22029)
* fix(kotlin-spring): add missing constructor parentheses for hashmap models This commit fixes a bug in the kotlin-spring generator where models defined with additionalProperties would result in uncompilable code. The generated data class was missing the constructor invocation '()' when inheriting from a map type. This has been corrected to only add parentheses when the parent is a map. The existing samples have been regenerated to reflect this change. * Trigger CI
1 parent e38f6c0 commit 44a3be1

38 files changed

+2699
-3
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
# server
3535
- samples/server/petstore/kotlin-server-required-and-nullable-properties
3636
- samples/server/petstore/kotlin-springboot-3
37+
- samples/server/petstore/kotlin-springboot-additionalproperties
3738
- samples/server/petstore/kotlin-springboot-delegate-nodefaults
3839
- samples/server/petstore/kotlin-springboot-request-cookie
3940
- samples/server/petstore/kotlin-server/jaxrs-spec
@@ -67,4 +68,4 @@ jobs:
6768
arguments: wrapper
6869
- name: Build
6970
working-directory: ${{ matrix.sample }}
70-
run: ./gradlew build -x test
71+
run: ./gradlew build -x test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ jobs:
7676
arguments: wrapper
7777
- name: Build
7878
working-directory: ${{ matrix.sample }}
79-
run: ./gradlew build -x test
79+
run: ./gradlew build -x test
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
generatorName: kotlin-spring
2+
outputDir: samples/server/petstore/kotlin-springboot-additionalproperties
3+
library: spring-boot
4+
inputSpec: samples/server/petstore/kotlin-springboot-additionalproperties/src/main/resources/openapi.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring
6+
additionalProperties:
7+
documentationProvider: none
8+
annotationLibrary: none
9+
useSwaggerUI: "false"
10+
serviceImplementation: "true"
11+
serializableModel: "true"
12+
beanValidations: "true"
13+
useSpringBoot3: "true"
14+
requestMappingMode: api_interface

modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>dataClassOptVar}}{{^-last}},
1919
{{/-last}}{{/optionalVars}}
2020
){{/discriminator}}{{! no newline
21-
}}{{#parent}} : {{{.}}}{{! no newline
21+
}}{{#parent}} : {{{.}}}{{#isMap}}(){{/isMap}}{{! no newline
2222
}}{{#serializableModel}}{{! no newline
2323
}}{{^vendorExtensions.x-kotlin-implements}}, Serializable{{/vendorExtensions.x-kotlin-implements}}{{! no newline
2424
}}{{#vendorExtensions.x-kotlin-implements}}, Serializable, {{! no newline
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
README.md
2+
build.gradle.kts
3+
gradle/wrapper/gradle-wrapper.jar
4+
gradle/wrapper/gradle-wrapper.properties
5+
gradlew
6+
gradlew.bat
7+
pom.xml
8+
settings.gradle
9+
src/main/kotlin/org/openapitools/Application.kt
10+
src/main/kotlin/org/openapitools/api/ApiUtil.kt
11+
src/main/kotlin/org/openapitools/api/Exceptions.kt
12+
src/main/kotlin/org/openapitools/api/PetApiController.kt
13+
src/main/kotlin/org/openapitools/api/PetApiService.kt
14+
src/main/kotlin/org/openapitools/api/PetApiServiceImpl.kt
15+
src/main/kotlin/org/openapitools/api/StoreApiController.kt
16+
src/main/kotlin/org/openapitools/api/StoreApiService.kt
17+
src/main/kotlin/org/openapitools/api/StoreApiServiceImpl.kt
18+
src/main/kotlin/org/openapitools/api/UserApiController.kt
19+
src/main/kotlin/org/openapitools/api/UserApiService.kt
20+
src/main/kotlin/org/openapitools/api/UserApiServiceImpl.kt
21+
src/main/kotlin/org/openapitools/model/Category.kt
22+
src/main/kotlin/org/openapitools/model/ModelApiResponse.kt
23+
src/main/kotlin/org/openapitools/model/Order.kt
24+
src/main/kotlin/org/openapitools/model/Pet.kt
25+
src/main/kotlin/org/openapitools/model/Tag.kt
26+
src/main/kotlin/org/openapitools/model/User.kt
27+
src/main/resources/application.yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.16.0-SNAPSHOT
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# openAPIPetstore
2+
3+
This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator).
4+
5+
## Getting Started
6+
7+
This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in.
8+
9+
By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl).
10+
11+
To build the project using maven, run:
12+
```bash
13+
mvn package && java -jar target/openapi-spring-1.0.0.jar
14+
```
15+
16+
To build the project using gradle, run:
17+
```bash
18+
gradle build && java -jar build/libs/openapi-spring-1.0.0.jar
19+
```
20+
21+
If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
group = "org.openapitools"
4+
version = "1.0.0"
5+
java.sourceCompatibility = JavaVersion.VERSION_17
6+
7+
repositories {
8+
mavenCentral()
9+
maven { url = uri("https://repo.spring.io/milestone") }
10+
}
11+
12+
tasks.withType<KotlinCompile> {
13+
kotlinOptions.jvmTarget = "17"
14+
}
15+
16+
plugins {
17+
val kotlinVersion = "1.9.25"
18+
id("org.jetbrains.kotlin.jvm") version kotlinVersion
19+
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
20+
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
21+
id("org.springframework.boot") version "3.0.2"
22+
id("io.spring.dependency-management") version "1.0.14.RELEASE"
23+
}
24+
25+
dependencies {
26+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
27+
implementation("org.jetbrains.kotlin:kotlin-reflect")
28+
implementation("org.springframework.boot:spring-boot-starter-web")
29+
30+
implementation("com.google.code.findbugs:jsr305:3.0.2")
31+
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
32+
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
33+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
34+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
35+
implementation("jakarta.validation:jakarta.validation-api")
36+
implementation("jakarta.annotation:jakarta.annotation-api:2.1.0")
37+
38+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
39+
testImplementation("org.springframework.boot:spring-boot-starter-test") {
40+
exclude(module = "junit")
41+
}
42+
}
42.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)