Skip to content

Commit 35cd79d

Browse files
committed
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.
1 parent dc0d5c6 commit 35cd79d

42 files changed

Lines changed: 2071 additions & 1 deletion

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
- samples/server/petstore/kotlin-server/ktor
4444
- samples/server/petstore/kotlin-server/ktor2
4545
- samples/server/petstore/kotlin-misk
46+
- samples/server/petstore/kotlin-springboot-additionalproperties
4647
# comment out due to gradle build failure
4748
# - samples/server/petstore/kotlin-spring-default/
4849
steps:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ jobs:
4949
- samples/server/others/kotlin-server/jaxrs-spec-array-response
5050
- samples/server/petstore/kotlin-spring-cloud
5151
- samples/server/petstore/kotlin-misk
52+
- samples/server/petstore/kotlin-springboot-additionalproperties
5253
- samples/server/petstore/kotlin-misk-config
5354
# comment out due to gradle build failure
5455
#- samples/server/petstore/kotlin-spring-default

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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/PetsApiController.kt
13+
src/main/kotlin/org/openapitools/api/PetsApiService.kt
14+
src/main/kotlin/org/openapitools/api/PetsApiServiceImpl.kt
15+
src/main/kotlin/org/openapitools/model/Error.kt
16+
src/main/kotlin/org/openapitools/model/Pet.kt
17+
src/main/resources/application.yaml
18+
src/test/kotlin/org/openapitools/api/PetsApiTest.kt
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+
# swaggerPetstore
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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
dependencies {
8+
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7")
9+
}
10+
}
11+
12+
group = "org.openapitools"
13+
version = "1.0.0"
14+
15+
repositories {
16+
mavenCentral()
17+
}
18+
19+
tasks.withType<KotlinCompile> {
20+
kotlinOptions.jvmTarget = "1.8"
21+
}
22+
23+
plugins {
24+
val kotlinVersion = "1.9.25"
25+
id("org.jetbrains.kotlin.jvm") version kotlinVersion
26+
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
27+
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
28+
id("org.springframework.boot") version "2.6.7"
29+
id("io.spring.dependency-management") version "1.0.11.RELEASE"
30+
}
31+
32+
dependencies {
33+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
34+
implementation("org.jetbrains.kotlin:kotlin-reflect")
35+
implementation("org.springframework.boot:spring-boot-starter-web")
36+
37+
implementation("com.google.code.findbugs:jsr305:3.0.2")
38+
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
39+
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
40+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
41+
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
42+
implementation("javax.validation:validation-api")
43+
implementation("javax.annotation:javax.annotation-api:1.3.2")
44+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
45+
testImplementation("org.springframework.boot:spring-boot-starter-test") {
46+
exclude(module = "junit")
47+
}
48+
}
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)