forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
@@ -4,6 +4,7 @@ import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.codegen.languages.features.BeanValidationFeatures;
|
||||
import io.swagger.codegen.languages.features.OptionalFeatures;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
@@ -15,7 +16,8 @@ import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
public class SpringCodegen extends AbstractJavaCodegen
|
||||
implements BeanValidationFeatures, OptionalFeatures {
|
||||
public static final String DEFAULT_LIBRARY = "spring-boot";
|
||||
public static final String TITLE = "title";
|
||||
public static final String CONFIG_PACKAGE = "configPackage";
|
||||
@@ -45,6 +47,7 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
protected boolean useBeanValidation = true;
|
||||
protected boolean implicitHeaders = false;
|
||||
protected boolean swaggerDocketConfig = false;
|
||||
protected boolean useOptional = false;
|
||||
|
||||
public SpringCodegen() {
|
||||
super();
|
||||
@@ -75,6 +78,8 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
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."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,
|
||||
"Use Optional container for optional parameters"));
|
||||
|
||||
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.");
|
||||
@@ -170,11 +175,14 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_OPTIONAL)) {
|
||||
this.setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
|
||||
}
|
||||
|
||||
if (useBeanValidation) {
|
||||
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(IMPLICIT_HEADERS)) {
|
||||
this.setImplicitHeaders(Boolean.valueOf(additionalProperties.get(IMPLICIT_HEADERS).toString()));
|
||||
}
|
||||
@@ -185,6 +193,10 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
|
||||
if (useOptional) {
|
||||
writePropertyBack(USE_OPTIONAL, useOptional);
|
||||
}
|
||||
|
||||
if (this.interfaceOnly && this.delegatePattern) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -649,4 +661,8 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseOptional(boolean useOptional) {
|
||||
this.useOptional = useOptional;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface OptionalFeatures {
|
||||
|
||||
// Language supports generating Optional Types
|
||||
String USE_OPTIONAL = "useOptional";
|
||||
|
||||
void setUseOptional(boolean useOptional);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user