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
feat(kotlin-spring): add Spring Boot 4 and Jackson 3 support (#23154)
* feat(kotlin): add Jackson 3 infrastructure to AbstractKotlinCodegen
* feat(kotlin-spring): add useSpringBoot4 and useJackson3 flags
* feat(kotlin-spring): update template selection for Spring Boot 4
* feat(kotlin-spring): add SB4 templates for all libraries
* test(kotlin-spring): add tests for Spring Boot 4 and Jackson 3 support
* feat(kotlin-spring): add kotlin-springboot-4 sample with Jackson 3
* docs(kotlin-spring): document useSpringBoot4 and useJackson3 options
* fix(kotlin-spring): update Gradle templates to Kotlin 2.2 JvmTarget DSL and bump CI Gradle
- Replace deprecated kotlinOptions.jvmTarget with kotlin.compilerOptions DSL
- Upgrade Gradle wrapper to 8.14 for Kotlin 2.2 compatibility
- Add kotlin-springboot-4 sample to JDK17 CI matrix
- Regenerate sample with updated templates
* fix(kotlin-spring): register useJackson3 CLI option and use Gradle 8.14 for SB4
- Add addSwitch for useJackson3 in KotlinSpringServerCodegen so it
appears in auto-generated docs
- Update gradle-wrapper.properties.mustache templates to use Gradle 8.14
when useSpringBoot4 is enabled (required minimum for Spring Boot 4)
* fix(kotlin-client): fix Jackson 3 package imports and add ktor/spring-restclient support
Replace hardcoded com.fasterxml.jackson imports with {{jacksonPackage}} template
variable across all kotlin-client templates so generated code compiles correctly
when useJackson3=true. Also fix trailing space in OAuth Bearer header, enable
useJackson3 for jvm-ktor (Ktor 3.4.0) and jvm-spring-restclient (Spring Boot 4),
and add conditional Jackson 3 dependencies in build.gradle.
* Revert "fix(kotlin-client): fix Jackson 3 package imports and add ktor/spring-restclient support"
Block useJackson3 for kotlin-client with a clear error until client
template support is added in a follow-up PR.
* ci: retrigger CI checks
* fix(kotlin-spring): replace legacy oauth2 starter and add Jackson exclusivity tests
Replace deprecated spring-cloud-starter-oauth2:2.2.5.RELEASE with
spring-boot-starter-oauth2-client in SB4 templates, as the legacy
starter is pre-Jakarta and incompatible with Spring Boot 4.
Add negative assertions to Jackson dependency tests to ensure Jackson 2
and Jackson 3 artifacts are mutually exclusive.
* feat(kotlin-spring): default to Jackson 3 when Spring Boot 4 is enabled
Spring Boot 4 ships with Jackson 3 out of the box, so useJackson3 now
defaults to true when useSpringBoot4 is enabled and the user hasn't
explicitly set useJackson3.
* fix(kotlin-spring): declare springdoc version property regardless of useSwaggerUI
The springdoc-openapi.version Maven property was only declared when
useSwaggerUI=true, but the springdoc core dependency (used when
useSwaggerUI=false) also references it, causing an undefined property.
* fix(kotlin-spring): use modern OAuth2 client config for Spring Boot 4 spring-cloud library
Add useSpringBoot4 conditionals to clientConfiguration.mustache so SB4
uses OAuth2AuthorizedClientManager instead of legacy OAuth2FeignRequestInterceptor
and *ResourceDetails classes that don't exist in Spring Boot 4.
* fix(kotlin-spring): default Jackson 3 when Spring Boot 4 set via setter or additionalProperties
The Jackson 3 defaulting logic only checked additionalProperties map,
so calling setUseSpringBoot4(true) via the Java API skipped the default.
Now checks both the field value and the map.
* fix(kotlin-spring): add trailing newline to clientConfiguration template
* Trigger CI
* clean up conditions
* fix(kotlin-spring): remove SB4+Jackson2 test since SB4 unconditionally implies Jackson 3
Spring Boot 4 ships with Jackson 3 — there is no supported SB4+Jackson2
combination, so the test was asserting an invalid scenario.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/generators/kotlin-spring.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,9 +59,11 @@ These options may be applied as additional-properties (cli) or configOptions (pl
59
59
|useBeanValidation|Use BeanValidation API annotations to validate data types||true|
60
60
|useFeignClientUrl|Whether to generate Feign client with url parameter.||true|
61
61
|useFlowForArrayReturnType|Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.||true|
62
+
|useJackson3|Use Jackson 3 dependencies (tools.jackson package). Only available with `useSpringBoot4`. Defaults to true when `useSpringBoot4` is enabled. Incompatible with `openApiNullable`.||false|
62
63
|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|
63
64
|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|
64
65
|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|
66
+
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x. Enabling this option will also enable `useJakartaEe`.||false|
65
67
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies||true|
66
68
|useTags|Whether to use tags for creating interface and controller class names||false|
67
69
|xKotlinImplementsFieldsSkip|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|
Copy file name to clipboardExpand all lines: docs/generators/kotlin.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
50
50
|sourceFolder|source folder for generated code||src/main/kotlin|
51
51
|supportAndroidApiLevel25AndBelow|[WARNING] This flag will generate code that has a known security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in order to support Android API level 25 and below. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284||false|
52
52
|useCoroutines|Whether to use the Coroutines adapter with the retrofit2 library.||false|
53
+
|useJackson3|Use Jackson 3 dependencies (tools.jackson package). Not yet supported for kotlin-client; reserved for future use.||false|
53
54
|useNonAsciiHeaders|Allow to use non-ascii headers with the okhttp library||false|
54
55
|useResponseAsReturnType|When using retrofit2 and coroutines, use `Response`<`T`> as return type instead of `T`.||true|
55
56
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library.||false|
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -298,6 +298,9 @@ public KotlinClientCodegen() {
298
298
299
299
cliOptions.add(CliOption.newBoolean(USE_NON_ASCII_HEADERS, "Allow to use non-ascii headers with the okhttp library"));
300
300
cliOptions.add(CliOption.newBoolean(USE_RESPONSE_AS_RETURN_TYPE, "When using retrofit2 and coroutines, use `Response`<`T`> as return type instead of `T`.", true));
@@ -254,6 +257,8 @@ public KotlinSpringServerCodegen() {
254
257
"@RestController annotations. May be used to prevent bean names clash if multiple generated libraries" +
255
258
" (contexts) added to single project.", beanQualifiers);
256
259
addSwitch(USE_SPRING_BOOT3, "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`.", useSpringBoot3);
260
+
addSwitch(USE_SPRING_BOOT4, "Generate code and provide dependencies for use with Spring Boot 4.x. Enabling this option will also enable `useJakartaEe`.", useSpringBoot4);
261
+
addSwitch(USE_JACKSON_3, "Use Jackson 3 dependencies (tools.jackson package). Only available with `useSpringBoot4`. Defaults to true when `useSpringBoot4` is enabled. Incompatible with `openApiNullable`.", useJackson3);
257
262
addSwitch(USE_FLOW_FOR_ARRAY_RETURN_TYPE, "Whether to use Flow for array/collection return types when reactive is enabled. If false, will use List instead.", useFlowForArrayReturnType);
258
263
addSwitch(INCLUDE_HTTP_REQUEST_CONTEXT, "Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods.", includeHttpRequestContext);
0 commit comments