Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.swagger.codegen.languages;

import io.swagger.codegen.*;
import io.swagger.codegen.languages.features.BeanValidationFeatures;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
Expand All @@ -10,7 +11,7 @@

import java.util.*;

public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen {
public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
/**
* Name of the sub-directory in "src/main/resource" where to find the
* Mustache template for the JAX-RS Codegen.
Expand All @@ -19,6 +20,9 @@ public abstract class AbstractJavaJAXRSServerCodegen extends AbstractJavaCodegen
protected String implFolder = "src/main/java";
protected String testResourcesFolder = "src/test/resources";
protected String title = "Swagger Server";

protected boolean useBeanValidation = true;

static Logger LOGGER = LoggerFactory.getLogger(AbstractJavaJAXRSServerCodegen.class);

public AbstractJavaJAXRSServerCodegen()
Expand All @@ -40,6 +44,8 @@ public AbstractJavaJAXRSServerCodegen()
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
cliOptions.add(new CliOption("title", "a title describing the application"));

cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));

}


Expand All @@ -60,6 +66,15 @@ public void processOpts() {
if (additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
}

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
}

if (useBeanValidation) {
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
}

}

@Override
Expand Down Expand Up @@ -204,4 +219,9 @@ public String apiFilename(String templateName, String tag) {
private String implFileFolder(String output) {
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
}

public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
protected boolean addConsumesProducesJson = true;

protected boolean useJaxbAnnotations = true;

protected boolean useBeanValidation = false;

protected boolean generateSpringApplication = false;

Expand All @@ -41,7 +39,7 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
protected boolean useWadlFeature = false;

protected boolean useMultipartFeature = false;

protected boolean useBeanValidationFeature = false;

protected boolean generateSpringBootApplication= false;
Expand Down Expand Up @@ -84,7 +82,6 @@ public JavaCXFServerCodegen()

cliOptions.add(CliOption.newBoolean(USE_JAXB_ANNOTATIONS, "Use JAXB annotations for XML"));

cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(GENERATE_SPRING_APPLICATION, "Generate Spring application"));
cliOptions.add(CliOption.newBoolean(USE_SPRING_ANNOTATION_CONFIG, "Use Spring Annotation Config"));

Expand Down Expand Up @@ -121,11 +118,6 @@ public void processOpts()
this.setUseJaxbAnnotations(useJaxbAnnotationsProp);
}

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
this.setUseBeanValidation(useBeanValidationProp);
}

if (additionalProperties.containsKey(ADD_CONSUMES_PRODUCES_JSON)) {
this.setAddConsumesProducesJson(convertPropertyToBooleanAndWriteBack(ADD_CONSUMES_PRODUCES_JSON));
}
Expand Down Expand Up @@ -224,10 +216,6 @@ public String getHelp()
return "Generates a Java JAXRS Server application based on Apache CXF framework.";
}

public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

public void setGenerateSpringApplication(boolean generateSpringApplication) {
this.generateSpringApplication = generateSpringApplication;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import io.swagger.models.properties.Property;
import io.swagger.util.Json;

public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen implements BeanValidationFeatures
public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen
{
protected boolean useBeanValidation = true;

public JavaJAXRSSpecServerCodegen()
{
Expand Down Expand Up @@ -71,23 +70,13 @@ public JavaJAXRSSpecServerCodegen()
library.setEnum(supportedLibraries);

cliOptions.add(library);

cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
}

@Override
public void processOpts()
{
super.processOpts();

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
}

if (useBeanValidation) {
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
}

supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));

Expand Down Expand Up @@ -159,9 +148,4 @@ public String getHelp()
{
return "Generates a Java JAXRS Server according to JAXRS 2.0 specification.";
}

public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen implements BeanValidationFeatures {
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {

protected static final String LIBRARY_JERSEY1 = "jersey1";
protected static final String LIBRARY_JERSEY2 = "jersey2";
protected boolean useBeanValidation = true;

/**
* Default library template to use. (Default:{@value #DEFAULT_LIBRARY})
Expand Down Expand Up @@ -47,7 +46,6 @@ public JavaJerseyServerCodegen() {

cliOptions.add(library);
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1/2 library."));
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
}

@Override
Expand Down Expand Up @@ -88,14 +86,6 @@ public void processOpts() {
setLibrary(DEFAULT_LIBRARY);
}

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
}

if (useBeanValidation) {
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
}

if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
}
Expand Down Expand Up @@ -172,8 +162,4 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
co.baseName = basePath;
}

public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import java.io.File;
import java.util.*;

public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen implements JbossFeature, BeanValidationFeatures {
public class JavaResteasyServerCodegen extends AbstractJavaJAXRSServerCodegen implements JbossFeature {

protected boolean useBeanValidation = true;
protected boolean generateJbossDeploymentDescriptor = true;

public JavaResteasyServerCodegen() {
Expand All @@ -37,7 +36,6 @@ public JavaResteasyServerCodegen() {

embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "resteasy";

cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(
CliOption.newBoolean(GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, "Generate Jboss Deployment Descriptor"));
}
Expand All @@ -62,14 +60,6 @@ public void processOpts() {
this.setGenerateJbossDeploymentDescriptor(generateJbossDeploymentDescriptorProp);
}

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
}

if (useBeanValidation) {
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
}

writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
writeOptional(outputFolder, new SupportingFile("gradle.mustache", "", "build.gradle"));
writeOptional(outputFolder, new SupportingFile("settingsGradle.mustache", "", "settings.gradle"));
Expand Down Expand Up @@ -226,10 +216,6 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
return objs;
}

public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

public void setGenerateJbossDeploymentDescriptor(boolean generateJbossDeploymentDescriptor) {
this.generateJbossDeploymentDescriptor = generateJbossDeploymentDescriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@
{{^minItems}}
{{#maxItems}}
@Size(max={{maxItems}})
{{/maxItems}}
{{/minItems}}
{{/maxItems}}
{{/minItems}}
{{! check for integer / number=decimal type}}
{{#isInteger}}
{{#minimum}}
{{#isInteger}}
@Min({{minimum}})
{{/isInteger}}
{{#isLong}}
@Min({{minimum}})
{{/isLong}}
{{/minimum}}
{{#maximum}}
{{#isInteger}}
@Max({{maximum}})
{{/isInteger}}
{{#isLong}}
@Max({{maximum}})
{{/isLong}}
{{/maximum}}
{{/isInteger}}
{{^isInteger}}
{{#minimum}}
@DecimalMin("{{minimum}}")
{{/minimum}}
{{#maximum}}
@DecimalMax("{{maximum}}")
{{/maximum}}
{{/isInteger}}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@
{{^minItems}}
{{#maxItems}}
@Size(max={{maxItems}})
{{/maxItems}}
{{/minItems}}
{{/maxItems}}
{{/minItems}}
{{! check for integer / number=decimal type}}
{{#isInteger}}
{{#minimum}}
@Min({{minimum}})
{{/minimum}}
{{#maximum}}
@Max({{maximum}})
{{/maximum}}
{{/maximum}}
{{/isInteger}}
{{^isInteger}}
{{#minimum}}
@DecimalMin("{{minimum}}")
{{/minimum}}
{{#maximum}}
@DecimalMax("{{maximum}}")
{{/maximum}}
{{/isInteger}}
Loading