mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-26 06:19:08 +00:00
[kotlin-spring] add reactive behavior via Kotlin coroutines (#2934)
* kotlin spring : add reactivity via kotlin's coroutines * add kotlin spring boot reactive samples * bug : fix spring version and import for coroutines * remove exception handler for reactive (webflux doesn't support it) * add spring milestone repository to maven pom * add reactive type for list in Api and ApiImpl methodes for mathching body responsive parameter * fix baseType for ArraySchema * regenerate samples * updating documentation
This commit is contained in:
committed by
Jim Schubert
parent
b74fa4458d
commit
7916f2f880
@@ -4707,7 +4707,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
codegenParameter.items = codegenProperty.items;
|
||||
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
|
||||
codegenParameter.dataType = getTypeDeclaration(arraySchema);
|
||||
codegenParameter.baseType = getSchemaType(arraySchema);
|
||||
codegenParameter.baseType = getSchemaType(inner);
|
||||
codegenParameter.isContainer = Boolean.TRUE;
|
||||
codegenParameter.isListContainer = Boolean.TRUE;
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
public static final String SWAGGER_ANNOTATIONS = "swaggerAnnotations";
|
||||
public static final String SERVICE_INTERFACE = "serviceInterface";
|
||||
public static final String SERVICE_IMPLEMENTATION = "serviceImplementation";
|
||||
public static final String REACTIVE = "reactive";
|
||||
|
||||
|
||||
private String basePackage;
|
||||
private String invokerPackage;
|
||||
@@ -72,6 +74,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
private boolean swaggerAnnotations = false;
|
||||
private boolean serviceInterface = false;
|
||||
private boolean serviceImplementation = false;
|
||||
private boolean reactive = false;
|
||||
|
||||
public KotlinSpringServerCodegen() {
|
||||
super();
|
||||
@@ -140,7 +143,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
addOption(SERVER_PORT, "configuration the port in which the sever is to run on", serverPort);
|
||||
addOption(CodegenConstants.MODEL_PACKAGE, "model package for generated code", modelPackage);
|
||||
addOption(CodegenConstants.API_PACKAGE, "api package for generated code", apiPackage);
|
||||
addSwitch(EXCEPTION_HANDLER, "generate default global exception handlers", exceptionHandler);
|
||||
addSwitch(EXCEPTION_HANDLER, "generate default global exception handlers (not compatible with reactive. enabling reactive will disable exceptionHandler )", exceptionHandler);
|
||||
addSwitch(GRADLE_BUILD_FILE, "generate a gradle build file using the Kotlin DSL", gradleBuildFile);
|
||||
addSwitch(SWAGGER_ANNOTATIONS, "generate swagger annotations to go alongside controllers and models", swaggerAnnotations);
|
||||
addSwitch(SERVICE_INTERFACE, "generate service interfaces to go alongside controllers. In most " +
|
||||
@@ -149,7 +152,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
addSwitch(SERVICE_IMPLEMENTATION, "generate stub service implementations that extends service " +
|
||||
"interfaces. If this is set to true service interfaces will also be generated", serviceImplementation);
|
||||
addSwitch(USE_BEANVALIDATION, "Use BeanValidation API annotations to validate data types", useBeanValidation);
|
||||
|
||||
addSwitch(REACTIVE, "use coroutines for reactive behavior", reactive);
|
||||
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
|
||||
setLibrary(SPRING_BOOT);
|
||||
|
||||
@@ -240,6 +243,14 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
public boolean isReactive() {
|
||||
return reactive;
|
||||
}
|
||||
|
||||
public void setReactive(boolean reactive) {
|
||||
this.reactive = reactive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
@@ -332,6 +343,14 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
|
||||
}
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
|
||||
if (additionalProperties.containsKey(REACTIVE) && library.equals(SPRING_BOOT)) {
|
||||
this.setReactive(convertPropertyToBoolean(REACTIVE));
|
||||
// spring webflux doesn't support @ControllerAdvice
|
||||
this.setExceptionHandler(false);
|
||||
}
|
||||
writePropertyBack(REACTIVE, reactive);
|
||||
writePropertyBack(EXCEPTION_HANDLER, exceptionHandler);
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".kt");
|
||||
apiTemplateFiles.put("api.mustache", ".kt");
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
Reference in New Issue
Block a user