Skip to content

Commit 103fdc3

Browse files
committed
feat(kotlin-spring): add useSpringBoot4 and useJackson3 flags
1 parent 945f21c commit 103fdc3

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
9191
public static final String DECLARATIVE_INTERFACE_REACTIVE_MODE = "declarativeInterfaceReactiveMode";
9292

9393
public static final String USE_SPRING_BOOT3 = "useSpringBoot3";
94+
public static final String USE_SPRING_BOOT4 = "useSpringBoot4";
9495
public static final String INCLUDE_HTTP_REQUEST_CONTEXT = "includeHttpRequestContext";
9596
public static final String USE_FLOW_FOR_ARRAY_RETURN_TYPE = "useFlowForArrayReturnType";
9697
public static final String REQUEST_MAPPING_OPTION = "requestMappingMode";
@@ -166,6 +167,8 @@ public String getDescription() {
166167

167168
@Getter @Setter
168169
protected boolean useSpringBoot3 = false;
170+
@Getter @Setter
171+
protected boolean useSpringBoot4 = false;
169172
protected RequestMappingMode requestMappingMode = RequestMappingMode.controller;
170173
private DocumentationProvider documentationProvider;
171174
private AnnotationLibrary annotationLibrary;
@@ -252,6 +255,7 @@ public KotlinSpringServerCodegen() {
252255
"@RestController annotations. May be used to prevent bean names clash if multiple generated libraries" +
253256
" (contexts) added to single project.", beanQualifiers);
254257
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);
258+
addSwitch(USE_SPRING_BOOT4, "Generate code and provide dependencies for use with Spring Boot 4.x. Enabling this option will also enable `useJakartaEe`.", useSpringBoot4);
255259
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);
256260
addSwitch(INCLUDE_HTTP_REQUEST_CONTEXT, "Whether to include HttpServletRequest (blocking) or ServerWebExchange (reactive) as additional parameter in generated methods.", includeHttpRequestContext);
257261
addSwitch(USE_RESPONSE_ENTITY,
@@ -464,6 +468,9 @@ public void processOpts() {
464468
if (additionalProperties.containsKey(USE_SPRING_BOOT3)) {
465469
this.setUseSpringBoot3(convertPropertyToBoolean(USE_SPRING_BOOT3));
466470
}
471+
if (additionalProperties.containsKey(USE_SPRING_BOOT4)) {
472+
this.setUseSpringBoot4(convertPropertyToBoolean(USE_SPRING_BOOT4));
473+
}
467474
if (additionalProperties.containsKey(INCLUDE_HTTP_REQUEST_CONTEXT)) {
468475
this.setIncludeHttpRequestContext(convertPropertyToBoolean(INCLUDE_HTTP_REQUEST_CONTEXT));
469476
}
@@ -490,6 +497,11 @@ public void processOpts() {
490497
// used later in recursive import in postProcessingModels
491498
importMapping.put("com.fasterxml.jackson.annotation.JsonProperty", "com.fasterxml.jackson.annotation.JsonCreator");
492499

500+
if (isUseJackson3()) {
501+
// Override databind imports for Jackson 3
502+
importMapping.put("JsonDeserialize", "tools.jackson.databind.annotation.JsonDeserialize");
503+
}
504+
493505
// Spring-specific import mappings for x-spring-paginated support
494506
importMapping.put("ApiIgnore", "springfox.documentation.annotations.ApiIgnore");
495507
importMapping.put("ParameterObject", "org.springdoc.api.annotations.ParameterObject");
@@ -680,7 +692,20 @@ public void processOpts() {
680692
this.setAutoXSpringPaginated(convertPropertyToBoolean(AUTO_X_SPRING_PAGINATED));
681693
}
682694
writePropertyBack(AUTO_X_SPRING_PAGINATED, autoXSpringPaginated);
683-
if (isUseSpringBoot3()) {
695+
if (isUseSpringBoot3() && isUseSpringBoot4()) {
696+
throw new IllegalArgumentException("Choose between Spring Boot 3 and Spring Boot 4");
697+
}
698+
699+
if (isUseJackson3() && !isUseSpringBoot4()) {
700+
throw new IllegalArgumentException("useJackson3 is only available with Spring Boot >= 4");
701+
}
702+
703+
if (isUseJackson3() && additionalProperties.containsKey("openApiNullable")
704+
&& Boolean.parseBoolean(additionalProperties.get("openApiNullable").toString())) {
705+
throw new IllegalArgumentException("openApiNullable cannot be set with useJackson3");
706+
}
707+
708+
if (isUseSpringBoot3() || isUseSpringBoot4()) {
684709
if (DocumentationProvider.SPRINGFOX.equals(getDocumentationProvider())) {
685710
throw new IllegalArgumentException(DocumentationProvider.SPRINGFOX.getPropertyName() + " is not supported with Spring Boot > 3.x");
686711
}
@@ -692,6 +717,7 @@ public void processOpts() {
692717
applyJakartaPackage();
693718
}
694719
writePropertyBack(USE_SPRING_BOOT3, isUseSpringBoot3());
720+
writePropertyBack(USE_SPRING_BOOT4, isUseSpringBoot4());
695721

696722
modelTemplateFiles.put("model.mustache", ".kt");
697723

0 commit comments

Comments
 (0)