forked from loafle/openapi-generator-original
add beanvalidation to jersey1 and jersey2 #4091
This commit is contained in:
@@ -2242,7 +2242,7 @@ public class DefaultCodegen {
|
||||
p.jsonSchema = Json.pretty(param);
|
||||
|
||||
if (System.getProperty("debugParser") != null) {
|
||||
LOGGER.info("working on Parameter " + param);
|
||||
LOGGER.info("working on Parameter " + param.getName());
|
||||
}
|
||||
|
||||
// move the defaultValue for headers, forms and params
|
||||
@@ -2271,7 +2271,7 @@ public class DefaultCodegen {
|
||||
String collectionFormat = null;
|
||||
String type = qp.getType();
|
||||
if (null == type) {
|
||||
LOGGER.warn("Type is NULL for Serializable Parameter: " + param);
|
||||
LOGGER.warn("Type is NULL for Serializable Parameter: " + param.getName());
|
||||
}
|
||||
if ("array".equals(type)) { // for array parameter
|
||||
Property inner = qp.getItems();
|
||||
|
||||
@@ -1000,5 +1000,18 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public String toRegularExpression(String pattern) {
|
||||
return escapeText(pattern);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 java.util.*;
|
||||
@@ -8,11 +9,12 @@ import java.util.*;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen implements BeanValidationFeatures {
|
||||
|
||||
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})
|
||||
*/
|
||||
@@ -45,6 +47,7 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
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
|
||||
@@ -84,6 +87,14 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
if (StringUtils.isEmpty(library)) {
|
||||
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);
|
||||
@@ -160,5 +171,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user