diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache index e0ef79f7c28d..bb9eca2fa466 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/homeController.mustache @@ -4,7 +4,7 @@ import org.springframework.context.annotation.Bean import org.springframework.stereotype.Controller import org.springframework.web.bind.annotation.RequestMapping {{#sourceDocumentationProvider}} -import com.fasterxml.jackson.dataformat.yaml.YAMLMapper +import {{jacksonPackage}}.dataformat.yaml.YAMLMapper import org.springframework.beans.factory.annotation.Value import org.springframework.core.io.Resource import org.springframework.util.StreamUtils diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradle-sb4-Kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradle-sb4-Kts.mustache index c9c5996d0e09..a18a859db71a 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradle-sb4-Kts.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/buildGradle-sb4-Kts.mustache @@ -46,9 +46,10 @@ dependencies { implementation("com.google.code.findbugs:jsr305:3.0.2") {{#useJackson3}} - implementation("tools.jackson.dataformat:jackson-dataformat-yaml") - implementation("tools.jackson.dataformat:jackson-dataformat-xml") - implementation("tools.jackson.module:jackson-module-kotlin") + val jackson3Version = "3.1.0" + implementation("tools.jackson.dataformat:jackson-dataformat-yaml:$jackson3Version") + implementation("tools.jackson.dataformat:jackson-dataformat-xml:$jackson3Version") + implementation("tools.jackson.module:jackson-module-kotlin:$jackson3Version") {{/useJackson3}} {{^useJackson3}} implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom-sb4.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom-sb4.mustache index 9d249a18caac..fc8eede4b8ad 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom-sb4.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-boot/pom-sb4.mustache @@ -11,7 +11,8 @@ 5.17.14{{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}} 1.6.6{{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}} 2.2.28{{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}} - 3.0.2 + 3.0.2{{#useJackson3}} + 3.1.0{{/useJackson3}} 3.0.0 2.2.0 @@ -158,22 +159,40 @@ jsr305 ${findbugs-jsr305.version} +{{#useJackson3}} {{jacksonPackage}}.dataformat jackson-dataformat-yaml + ${jackson3.version} {{jacksonPackage}}.dataformat jackson-dataformat-xml - {{^useJackson3}} + ${jackson3.version} + + + {{jacksonPackage}}.module + jackson-module-kotlin + ${jackson3.version} + +{{/useJackson3}}{{^useJackson3}} + + {{jacksonPackage}}.dataformat + jackson-dataformat-yaml + + + {{jacksonPackage}}.dataformat + jackson-dataformat-xml + com.fasterxml.jackson.datatype jackson-datatype-jsr310 - {{/useJackson3}} + {{jacksonPackage}}.module jackson-module-kotlin +{{/useJackson3}} {{#useBeanValidation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/buildGradle-sb4-Kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/buildGradle-sb4-Kts.mustache index 80d88024a89b..bf52cff383e6 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/buildGradle-sb4-Kts.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/buildGradle-sb4-Kts.mustache @@ -54,9 +54,10 @@ dependencies { implementation("com.google.code.findbugs:jsr305:3.0.2") {{#useJackson3}} - implementation("tools.jackson.dataformat:jackson-dataformat-yaml") - implementation("tools.jackson.dataformat:jackson-dataformat-xml") - implementation("tools.jackson.module:jackson-module-kotlin") + val jackson3Version = "3.1.0" + implementation("tools.jackson.dataformat:jackson-dataformat-yaml:$jackson3Version") + implementation("tools.jackson.dataformat:jackson-dataformat-xml:$jackson3Version") + implementation("tools.jackson.module:jackson-module-kotlin:$jackson3Version") {{/useJackson3}} {{^useJackson3}} implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/pom-sb4.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/pom-sb4.mustache index b2701ebf9635..8615b298bf3b 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/pom-sb4.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-cloud/pom-sb4.mustache @@ -17,7 +17,8 @@ {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}} 2.2.28 {{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}} - 3.0.2 + 3.0.2{{#useJackson3}} + 3.1.0{{/useJackson3}} 3.0.0 2.2.0 @@ -183,22 +184,40 @@ spring-boot-starter-oauth2-client {{/hasAuthMethods}} +{{#useJackson3}} {{jacksonPackage}}.dataformat jackson-dataformat-yaml + ${jackson3.version} {{jacksonPackage}}.dataformat jackson-dataformat-xml - {{^useJackson3}} + ${jackson3.version} + + + {{jacksonPackage}}.module + jackson-module-kotlin + ${jackson3.version} + +{{/useJackson3}}{{^useJackson3}} + + {{jacksonPackage}}.dataformat + jackson-dataformat-yaml + + + {{jacksonPackage}}.dataformat + jackson-dataformat-xml + com.fasterxml.jackson.datatype jackson-datatype-jsr310 - {{/useJackson3}} + {{jacksonPackage}}.module jackson-module-kotlin +{{/useJackson3}} {{#useBeanValidation}} diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/buildGradle-sb4-Kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/buildGradle-sb4-Kts.mustache index bc05ca9c9cb3..72aa154c8a18 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/buildGradle-sb4-Kts.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/buildGradle-sb4-Kts.mustache @@ -54,9 +54,10 @@ dependencies { implementation("com.google.code.findbugs:jsr305:3.0.2") {{#useJackson3}} - implementation("tools.jackson.dataformat:jackson-dataformat-yaml") - implementation("tools.jackson.dataformat:jackson-dataformat-xml") - implementation("tools.jackson.module:jackson-module-kotlin") + val jackson3Version = "3.1.0" + implementation("tools.jackson.dataformat:jackson-dataformat-yaml:$jackson3Version") + implementation("tools.jackson.dataformat:jackson-dataformat-xml:$jackson3Version") + implementation("tools.jackson.module:jackson-module-kotlin:$jackson3Version") {{/useJackson3}} {{^useJackson3}} implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml") diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/pom-sb4.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/pom-sb4.mustache index d46488af57e1..4ce93ab8e4dd 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/pom-sb4.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/libraries/spring-declarative-http-interface/pom-sb4.mustache @@ -17,7 +17,8 @@ {{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}} 2.2.28 {{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}} - 3.0.2 + 3.0.2{{#useJackson3}} + 3.1.0{{/useJackson3}} 3.0.0 2.2.0 @@ -179,22 +180,40 @@ spring-boot-starter-oauth2-client {{/hasAuthMethods}} +{{#useJackson3}} {{jacksonPackage}}.dataformat jackson-dataformat-yaml + ${jackson3.version} {{jacksonPackage}}.dataformat jackson-dataformat-xml - {{^useJackson3}} + ${jackson3.version} + + + {{jacksonPackage}}.module + jackson-module-kotlin + ${jackson3.version} + +{{/useJackson3}}{{^useJackson3}} + + {{jacksonPackage}}.dataformat + jackson-dataformat-yaml + + + {{jacksonPackage}}.dataformat + jackson-dataformat-xml + com.fasterxml.jackson.datatype jackson-datatype-jsr310 - {{/useJackson3}} + {{jacksonPackage}}.module jackson-module-kotlin +{{/useJackson3}} {{#useBeanValidation}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java index dc250555135b..3bbfc319ba93 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java @@ -4825,6 +4825,42 @@ public void shouldGenerateSpringBoot4PomWithJackson3Deps() throws IOException { assertFileNotContains(pomPath, "com.fasterxml.jackson.module"); } + @Test + public void shouldGenerateJackson3BuildDepsWithVersions() throws IOException { + File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); + output.deleteOnExit(); + String outputPath = output.getAbsolutePath().replace('\\', '/'); + + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml"); + final KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen(); + codegen.setOpenAPI(openAPI); + codegen.setOutputDir(output.getAbsolutePath()); + + codegen.additionalProperties().put(KotlinSpringServerCodegen.USE_SPRING_BOOT4, "true"); + codegen.additionalProperties().put(AbstractKotlinCodegen.USE_JACKSON_3, "true"); + codegen.additionalProperties().put(DOCUMENTATION_PROVIDER, DocumentationProvider.NONE.toCliOptValue()); + codegen.additionalProperties().put(ANNOTATION_LIBRARY, AnnotationLibrary.NONE.toCliOptValue()); + + ClientOptInput input = new ClientOptInput(); + input.openAPI(openAPI); + input.config(codegen); + + DefaultGenerator generator = new DefaultGenerator(); + generator.setGenerateMetadata(false); + generator.opts(input).generate(); + + // Gradle build file must have Jackson 3 deps with explicit versions + Path gradlePath = Paths.get(outputPath + "/build.gradle.kts"); + assertFileContains(gradlePath, "tools.jackson.dataformat:jackson-dataformat-yaml:"); + assertFileContains(gradlePath, "tools.jackson.module:jackson-module-kotlin:"); + // Should NOT include non-existent tools.jackson.core:jackson-annotations + assertFileNotContains(gradlePath, "tools.jackson.core:jackson-annotations"); + + // Annotations stay in com.fasterxml.jackson.annotation even with Jackson 3 + Path petModelPath = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt"); + assertFileContains(petModelPath, "com.fasterxml.jackson.annotation.JsonProperty"); + } + @Test public void shouldDefaultToJackson3WhenSpringBoot4Enabled() throws IOException { File output = Files.createTempDirectory("test").toFile().getCanonicalFile(); diff --git a/samples/server/petstore/kotlin-springboot-4/build.gradle.kts b/samples/server/petstore/kotlin-springboot-4/build.gradle.kts index 3459856672ac..e33832d4074e 100644 --- a/samples/server/petstore/kotlin-springboot-4/build.gradle.kts +++ b/samples/server/petstore/kotlin-springboot-4/build.gradle.kts @@ -29,9 +29,10 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-webmvc") implementation("com.google.code.findbugs:jsr305:3.0.2") - implementation("tools.jackson.dataformat:jackson-dataformat-yaml") - implementation("tools.jackson.dataformat:jackson-dataformat-xml") - implementation("tools.jackson.module:jackson-module-kotlin") + val jackson3Version = "3.1.0" + implementation("tools.jackson.dataformat:jackson-dataformat-yaml:$jackson3Version") + implementation("tools.jackson.dataformat:jackson-dataformat-xml:$jackson3Version") + implementation("tools.jackson.module:jackson-module-kotlin:$jackson3Version") implementation("org.springframework.data:spring-data-commons") implementation("jakarta.validation:jakarta.validation-api") implementation("jakarta.annotation:jakarta.annotation-api:3.0.0") diff --git a/samples/server/petstore/kotlin-springboot-4/pom.xml b/samples/server/petstore/kotlin-springboot-4/pom.xml index 3ce44dbf761c..e7f8c70c453e 100644 --- a/samples/server/petstore/kotlin-springboot-4/pom.xml +++ b/samples/server/petstore/kotlin-springboot-4/pom.xml @@ -7,6 +7,7 @@ 1.0.0 3.0.2 + 3.1.0 3.0.0 2.2.0 @@ -101,14 +102,17 @@ tools.jackson.dataformat jackson-dataformat-yaml + ${jackson3.version} tools.jackson.dataformat jackson-dataformat-xml + ${jackson3.version} tools.jackson.module jackson-module-kotlin + ${jackson3.version}