forked from loafle/openapi-generator-original
[spring] improve build-time code generation, for CI and maven integration (#5545)
* Do not generate pom.xml and README.md when interfaceOnly=true #5542 * New swaggerDocketConfig option, to generate Spring configuration class for Swagger Docket bean. Ignored when interfaceOnly=false or library=spring-cloud #5542 * Updated tests running ./bin/spring-all-petstore.sh * Run ./bin/spring-all-petstore.sh
This commit is contained in:
@@ -30,6 +30,7 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
public static final String SPRING_MVC_LIBRARY = "spring-mvc";
|
||||
public static final String SPRING_CLOUD_LIBRARY = "spring-cloud";
|
||||
public static final String IMPLICIT_HEADERS = "implicitHeaders";
|
||||
public static final String SWAGGER_DOCKET_CONFIG = "swaggerDocketConfig";
|
||||
|
||||
protected String title = "swagger-petstore";
|
||||
protected String configPackage = "io.swagger.configuration";
|
||||
@@ -43,6 +44,7 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
protected boolean useTags = false;
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected boolean swaggerDocketConfig = false;
|
||||
|
||||
public SpringCodegen() {
|
||||
super();
|
||||
@@ -72,6 +74,7 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Use of @ApiImplicitParams for headers."));
|
||||
cliOptions.add(CliOption.newBoolean(SWAGGER_DOCKET_CONFIG, "Generate Spring Swagger Docket configuration class."));
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Spring-boot Server application using the SpringFox integration.");
|
||||
supportedLibraries.put(SPRING_MVC_LIBRARY, "Spring-MVC Server application using the SpringFox integration.");
|
||||
@@ -176,18 +179,22 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
this.setImplicitHeaders(Boolean.valueOf(additionalProperties.get(IMPLICIT_HEADERS).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SWAGGER_DOCKET_CONFIG)) {
|
||||
this.setSwaggerDocketConfig(Boolean.valueOf(additionalProperties.get(SWAGGER_DOCKET_CONFIG).toString()));
|
||||
}
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
if (this.interfaceOnly && this.delegatePattern) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Can not generate code with `%s` and `%s` both true.", DELEGATE_PATTERN, INTERFACE_ONLY));
|
||||
}
|
||||
|
||||
if (!this.interfaceOnly) {
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
if (library.equals(DEFAULT_LIBRARY)) {
|
||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||
@@ -235,6 +242,9 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
supportingFiles.add(new SupportingFile("swaggerDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerDocumentationConfig.java"));
|
||||
}
|
||||
} else if ( this.swaggerDocketConfig && !library.equals(SPRING_CLOUD_LIBRARY)) {
|
||||
supportingFiles.add(new SupportingFile("swaggerDocumentationConfig.mustache",
|
||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "SwaggerDocumentationConfig.java"));
|
||||
}
|
||||
|
||||
if ("threetenbp".equals(dateLibrary)) {
|
||||
@@ -586,6 +596,10 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
this.implicitHeaders = implicitHeaders;
|
||||
}
|
||||
|
||||
public void setSwaggerDocketConfig(boolean swaggerDocketConfig) {
|
||||
this.swaggerDocketConfig = swaggerDocketConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
||||
Reference in New Issue
Block a user