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
Expand Up @@ -346,7 +346,7 @@ public void processSwagger(Swagger swagger) {
// override with any special handling of the JMustache compiler
@SuppressWarnings("unused")
public Compiler processCompiler(Compiler compiler) {
return compiler;
return compiler;
}

// override with any special text escaping logic
Expand Down Expand Up @@ -1680,7 +1680,7 @@ public CodegenProperty fromProperty(String name, Property p) {

property.baseType = getSwaggerType(p);

if (p instanceof ArrayProperty) {
if (p instanceof ArrayProperty) {
property.isContainer = true;
property.isListContainer = true;
property.containerType = "array";
Expand All @@ -1689,7 +1689,7 @@ public CodegenProperty fromProperty(String name, Property p) {
ArrayProperty ap = (ArrayProperty) p;
CodegenProperty cp = fromProperty(property.name, ap.getItems());
updatePropertyForArray(property, cp);
} else if (p instanceof MapProperty) {
} else if (p instanceof MapProperty) {
property.isContainer = true;
property.isMapContainer = true;
property.containerType = "map";
Expand Down Expand Up @@ -1876,7 +1876,7 @@ protected Response findMethodResponse(Map<String, Response> responses) {
* @return Codegen Operation object
*/
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
return fromOperation(path, httpMethod, operation, definitions, null);
return fromOperation(path, httpMethod, operation, definitions, null);
}

/**
Expand Down Expand Up @@ -2531,7 +2531,7 @@ public boolean isDataTypeFile(String dataType) {
@SuppressWarnings("static-method")
public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition> schemes) {
if (schemes == null) {
return Collections.emptyList();
return Collections.emptyList();
}

List<CodegenSecurity> secs = new ArrayList<CodegenSecurity>(schemes.size());
Expand All @@ -2555,8 +2555,8 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition>
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isOAuth = false;
sec.isBasic = true;
} else {
final OAuth2Definition oauth2Definition = (OAuth2Definition) schemeDefinition;
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isBasic = false;
final OAuth2Definition oauth2Definition = (OAuth2Definition) schemeDefinition;
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isBasic = false;
sec.isOAuth = true;
sec.flow = oauth2Definition.getFlow();
if (sec.flow == null) {
Expand Down Expand Up @@ -3191,11 +3191,11 @@ public String sanitizeName(String name) {
// encountered so far and hopefully make it easier for others to add more special
// cases in the future.

// better error handling when map/array type is invalid
if (name == null) {
LOGGER.error("String to be sanitized is null. Default to ERROR_UNKNOWN");
return "ERROR_UNKNOWN";
}
// better error handling when map/array type is invalid
if (name == null) {
LOGGER.error("String to be sanitized is null. Default to ERROR_UNKNOWN");
return "ERROR_UNKNOWN";
}

// if the name is just '$', map it to 'value' for the time being.
if ("$".equals(name)) {
Expand Down Expand Up @@ -3416,11 +3416,25 @@ public String addRegularExpressionDelimiter(String pattern) {
public boolean convertPropertyToBooleanAndWriteBack(String propertyKey) {
boolean booleanValue = false;
if (additionalProperties.containsKey(propertyKey)) {
booleanValue = Boolean.valueOf(additionalProperties.get(propertyKey).toString());
booleanValue = convertPropertyToBoolean(propertyKey);
// write back as boolean
additionalProperties.put(propertyKey, booleanValue);
writePropertyBack(propertyKey, booleanValue);
}

return booleanValue;
}


public boolean convertPropertyToBoolean(String propertyKey) {
boolean booleanValue = false;
if (additionalProperties.containsKey(propertyKey)) {
booleanValue = Boolean.valueOf(additionalProperties.get(propertyKey).toString());
}

return booleanValue;
}

public void writePropertyBack(String propertyKey, boolean value) {
additionalProperties.put(propertyKey, value);
}
}
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.codegen.languages.features.JbossFeature;
import io.swagger.models.Operation;
import org.apache.commons.lang3.BooleanUtils;
Expand All @@ -9,10 +10,11 @@
import java.io.File;
import java.util.*;

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

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

public JavaResteasyServerCodegen() {

super();
Expand All @@ -35,6 +37,7 @@ 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 @@ -58,6 +61,14 @@ public void processOpts() {
GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR);
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"));
Expand Down Expand Up @@ -214,6 +225,10 @@ 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 @@ -16,6 +16,9 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
{{#useBeanValidation}}
import javax.validation.constraints.*;
{{/useBeanValidation}}
{{#operations}}{{#operation}}{{#isMultipart}}import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
{{/isMultipart}}{{/operation}}{{/operations}}
@Path("/{{baseName}}")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{#required}}
@NotNull
{{/required}}
{{#pattern}}
@Pattern(regexp="{{pattern}}")
{{/pattern}}
{{#minLength}}
{{#maxLength}}
@Size(min={{minLength}},max={{maxLength}})
{{/maxLength}}
{{/minLength}}
{{#minLength}}
{{^maxLength}}
@Size(min={{minLength}})
{{/maxLength}}
{{/minLength}}
{{^minLength}}
{{#maxLength}}
@Size(max={{maxLength}})
{{/maxLength}}
{{/minLength}}
{{#minItems}}
{{#maxItems}}
@Size(min={{minItems}},max={{maxItems}})
{{/maxItems}}
{{/minItems}}
{{#minItems}}
{{^maxItems}}
@Size(min={{minItems}})
{{/maxItems}}
{{/minItems}}
{{^minItems}}
{{#maxItems}}
@Size(max={{maxItems}})
{{/maxItems}}
{{/minItems}}
{{! check for integer / number=decimal type}}
{{#isInteger}}
{{#minimum}}
@Min({{minimum}})
{{/minimum}}
{{#maximum}}
@Max({{maximum}})
{{/maximum}}
{{/isInteger}}
{{^isInteger}}
{{#minimum}}
@DecimalMin("{{minimum}}")
{{/minimum}}
{{#maximum}}
@DecimalMax("{{maximum}}")
{{/maximum}}
{{/isInteger}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{! PathParam is always required, no @NotNull necessary }}{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#required}} @NotNull{{/required}}{{#pattern}} @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} @Size(min={{minLength}}){{/maxLength}}{{/minLength}}{{^minLength}}{{#maxLength}} @Size(max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minItems}}{{#maxItems}} @Size(min={{minItems}},max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minItems}}{{^maxItems}} @Size(min={{minItems}}){{/maxItems}}{{/minItems}}{{^minItems}}{{#maxItems}} @Size(max={{maxItems}}){{/maxItems}}{{/minItems}}{{#minimum}} @Min({{minimum}}){{/minimum}}{{#maximum}} @Max({{maximum}}){{/maximum}}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import java.util.ArrayList;
{{#serializableModel}}
import java.io.Serializable;
{{/serializableModel}}

{{#useBeanValidation}}
import javax.validation.constraints.*;
{{/useBeanValidation}}
{{#models}}
{{#model}}
{{#isEnum}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isPathParam}} @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
{{#isPathParam}}{{#useBeanValidation}}{{>beanValidationPathParams}}{{/useBeanValidation}} @PathParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isPathParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
**/
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
@JsonProperty("{{baseName}}")
public {{{datatypeWithEnum}}} {{getter}}() {
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@
</exclusion>
</exclusions>
</dependency>
{{#useBeanValidation}}
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
{{/useBeanValidation}}

</dependencies>
<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isQueryParam}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
{{#isQueryParam}}{{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}} @QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ protected void setExpectations() {

clientCodegen.setGenerateJbossDeploymentDescriptor(
Boolean.valueOf(JavaResteasyServerOptionsProvider.GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR));

clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaResteasyServerOptionsProvider.USE_BEANVALIDATION));
times = 1;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@

import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.languages.JavaCXFServerCodegen;
import io.swagger.codegen.languages.JavaResteasyServerCodegen;

public class JavaResteasyServerOptionsProvider extends JavaOptionsProvider {

public static final String GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR = "true";

public static final String IMPL_FOLDER_VALUE = "src/main/java";

public static final String USE_BEANVALIDATION = "true";

@Override
public boolean isServer() {
return true;
Expand All @@ -35,6 +38,7 @@ public Map<String, String> createOptions() {
builder.put("title", "Test title");

builder.put(JavaCXFServerCodegen.GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR, GENERATE_JBOSS_DEPLOYMENT_DESCRIPTOR);
builder.put(JavaResteasyServerCodegen.USE_BEANVALIDATION, USE_BEANVALIDATION);

return builder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
import javax.validation.constraints.*;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;

@Path("/pet")
Expand Down Expand Up @@ -46,15 +47,15 @@ public Response deletePet( @PathParam("petId") Long petId,@HeaderParam("api_key"
@Path("/findByStatus")

@Produces({ "application/xml", "application/json" })
public Response findPetsByStatus( @QueryParam("status") List<String> status,@Context SecurityContext securityContext)
public Response findPetsByStatus( @NotNull @QueryParam("status") List<String> status,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.findPetsByStatus(status,securityContext);
}
@GET
@Path("/findByTags")

@Produces({ "application/xml", "application/json" })
public Response findPetsByTags( @QueryParam("tags") List<String> tags,@Context SecurityContext securityContext)
public Response findPetsByTags( @NotNull @QueryParam("tags") List<String> tags,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.findPetsByTags(tags,securityContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
import javax.validation.constraints.*;

@Path("/store")

Expand All @@ -28,7 +29,7 @@ public class StoreApi {
@Path("/order/{orderId}")

@Produces({ "application/xml", "application/json" })
public Response deleteOrder( @PathParam("orderId") String orderId,@Context SecurityContext securityContext)
public Response deleteOrder( @Min(1) @PathParam("orderId") String orderId,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.deleteOrder(orderId,securityContext);
}
Expand All @@ -44,7 +45,7 @@ public Response getInventory(@Context SecurityContext securityContext)
@Path("/order/{orderId}")

@Produces({ "application/xml", "application/json" })
public Response getOrderById( @PathParam("orderId") Long orderId,@Context SecurityContext securityContext)
public Response getOrderById( @Min(1) @Max(5) @PathParam("orderId") Long orderId,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.getOrderById(orderId,securityContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.*;
import javax.validation.constraints.*;

@Path("/user")

Expand Down Expand Up @@ -68,7 +69,7 @@ public Response getUserByName( @PathParam("username") String username,@Context S
@Path("/login")

@Produces({ "application/xml", "application/json" })
public Response loginUser( @QueryParam("username") String username, @QueryParam("password") String password,@Context SecurityContext securityContext)
public Response loginUser( @NotNull @QueryParam("username") String username, @NotNull @QueryParam("password") String password,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.loginUser(username,password,securityContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;

import javax.validation.constraints.*;

public class Category {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.annotations.ApiModel;

import javax.validation.constraints.*;

public class ModelApiResponse {

Expand Down
Loading