forked from loafle/openapi-generator-original
[Java] BeanValidation + JAXRS CXF server generator (#4068)
* add pom-file to cxf including cxf-client #2017 * adapt pom sourceFolder in pom.mustache to gen/java #2017 * add test templates for CXF #2017 * optimize mustache template structure, remove tabs #3280 #2549 * refined dependency to swagger-jaxrs #2017 * refined annotations and line breaks #2549 * fix tabs instead of spaces... * move annotations from getter to field for server model * cleanup tabs * add example for gzipping #2017 * add complete WAR to cxf-server #2017 * add readme + rework pom #2017 * add cli switch for beanvalidation #2549 * move beanvalidation into separate subtemplate and reuse for cxf * add beanValidation java template * corrected path to mustache file * fix AbstractOptionsTest, add default false for USE_BEANVALIDATION * add pom-file to cxf including cxf-client #2017 * adapt pom sourceFolder in pom.mustache to gen/java #2017 * add test templates for CXF #2017 * optimize mustache template structure, remove tabs #3280 #2549 * refined dependency to swagger-jaxrs #2017 * refined annotations and line breaks #2549 * fix tabs instead of spaces... * move annotations from getter to field for server model * cleanup tabs * add example for gzipping #2017 * add complete WAR to cxf-server #2017 * add readme + rework pom #2017 * add cli switch for beanvalidation #2549 * move beanvalidation into separate subtemplate and reuse for cxf * add beanValidation java template * corrected path to mustache file * fix AbstractOptionsTest, add default false for USE_BEANVALIDATION * add beanvalidation to okhttp-gson library #2549 * cleanup api.mustache for cxf #3281 * temporary fix for invalid BeanValidation-pattern with / #2549 * temporary fix for invalid BeanValidation-pattern with / #2549 * remove jaxrs-annotations from implementation classes #3281 * add configuration to generate spring web application #4003 * clean up unnecessary @Path annotation (part of method level!) * add support for minItems/maxItems #2549 * add support for BeanValidation for query params #2549 * add imports for bean validation #2549 * add switches for various cxf server features #2017 * fix tests #2549 #2017 * re-create bin folder * cleanup * cleanup * Revert "temporary solution for pattern - move to AbstractJavaCodegen #2549" This reverts commit 82df5e657f31303bcb7d38f1dc013183d3509da2, reversing changes made to 65e87f23a6804a0d5c0926c916a9cd6866e7fee0. Conflicts: bin/akka-scala-petstore.sh bin/android-petstore-all.sh bin/android-petstore-httpclient.sh bin/android-petstore-volley.sh bin/android-petstore.sh bin/aspnet5-petstore-server.sh bin/clojure-petstore.sh bin/cpprest-petstore.sh bin/csharp-dotnet2-petstore.sh bin/csharp-petstore-all.sh bin/csharp-petstore.sh bin/csharp-property-changed-petstore.sh bin/cwiki-petstore.sh bin/dart-petstore.sh bin/dynamic-html.sh bin/erlang-petstore-server.sh bin/flash-petstore.sh bin/flaskConnexion-python2.sh bin/flaskConnexion.sh bin/go-petstore-server.sh bin/go-petstore.sh bin/groovy-petstore.sh bin/haskell-servant-petstore.sh bin/html-petstore.sh bin/html2-petstore.sh bin/java-inflector-petstore-server.sh bin/java-petstore-all.sh bin/java-petstore-feign.sh bin/java-petstore-jersey1.sh bin/java-petstore-jersey2.sh bin/java-petstore-okhttp-gson-parcelable.sh bin/java-petstore-okhttp-gson.sh bin/java-petstore-retrofit.sh bin/java-petstore-retrofit2.sh bin/java-petstore-retrofit2rx.sh bin/java-undertow-petstore-server.sh bin/java8-petstore-jersey2.sh bin/javascript-closure-angular.sh bin/javascript-petstore-all.sh bin/javascript-petstore.sh bin/javascript-promise-petstore.sh bin/jaxrs-cxf-cdi-petstore-server.sh bin/jaxrs-cxf-petstore-server.sh bin/jaxrs-jersey1-petstore-server.sh bin/jaxrs-petstore-server.sh bin/jaxrs-resteasy-joda-petstore-server.json bin/jaxrs-resteasy-joda-petstore-server.sh bin/jaxrs-resteasy-petstore-server.sh bin/jaxrs-spec-petstore-server.sh bin/jmeter-petstore.sh bin/lumen-petstore-server.sh bin/nancyfx-petstore-server.sh bin/nodejs-petstore-server.sh bin/objc-petstore-all.sh bin/objc-petstore-coredata.sh bin/objc-petstore.sh bin/perl-petstore.sh bin/php-petstore.sh bin/python-petstore.sh bin/qt5-petstore.sh bin/rails5-petstore-server.sh bin/ruby-petstore.sh bin/run-all-petstore bin/scala-async-petstore.sh bin/scala-petstore.sh bin/scalatra-petstore-server.sh bin/security/csharp-petstore.sh bin/security/go-petstore.sh bin/security/java-petstore-okhttp-gson.sh bin/security/javascript-closure-angular.sh bin/security/javascript-petstore.sh bin/security/lumen-petstore-server.sh bin/security/objc-petstore.sh bin/security/perl-petstore.sh bin/security/php-petstore.sh bin/security/python-petstore.sh bin/security/qt5cpp-petstore.sh bin/security/ruby-petstore.sh bin/security/run-all-petstore-security-test bin/security/scala-petstore.sh bin/security/silex-petstore-server.sh bin/security/slim-petstore-server.sh bin/security/swift-petstore.sh bin/security/typescript-angular.sh bin/security/typescript-angular2.sh bin/security/typescript-fetch.sh bin/security/typescript-node.sh bin/silex-petstore-server.sh bin/sinatra-petstore-server.sh bin/slim-petstore-server.sh bin/spring-all-pestore.sh bin/spring-cloud-feign-petstore.sh bin/spring-mvc-petstore-j8-async-server.sh bin/spring-mvc-petstore-server.sh bin/spring-stubs.sh bin/springboot-petstore-server.sh bin/swift-petstore-all.sh bin/swift-petstore-promisekit.sh bin/swift-petstore-rxswift.sh bin/swift-petstore.sh bin/tizen-petstore.sh bin/typescript-angular-petstore.sh bin/typescript-angular2-petstore-all.sh bin/typescript-angular2-petstore-with-npm.sh bin/typescript-angular2-petstore.sh bin/typescript-fetch-petstore-all.sh bin/typescript-fetch-petstore-target-es6.sh bin/typescript-fetch-petstore-with-npm-version.sh bin/typescript-fetch-petstore.sh bin/typescript-node-petstore-all.sh bin/typescript-node-petstore-with-npm.sh bin/typescript-node-petstore.sh bin/typescript-petstore-npm.json bin/windows/akka-scala-petstore.bat bin/windows/android-petstore.bat bin/windows/aspnet5-petstore-server.bat bin/windows/async-scala-petstore.bat bin/windows/clojure-petstore.bat bin/windows/cpprest-petstore.bat bin/windows/csharp-petstore.bat bin/windows/dart-petstore.bat bin/windows/dynamic-html-petstore.bat bin/windows/flash-petstore.bat bin/windows/go-petstore.bat bin/windows/html-petstore.bat bin/windows/java-petstore-okhttp-gson.bat bin/windows/java-petstore.bat bin/windows/javascript-petstore.bat bin/windows/objc-petstore.bat bin/windows/perl-petstore.bat bin/windows/php-petstore.bat bin/windows/python-petstore.bat bin/windows/qt5cpp-petstore.bat bin/windows/rails5-petstore-server.bat bin/windows/ruby-petstore.bat bin/windows/scala-petstore.bat bin/windows/spring-mvc-petstore-j8-async-server.bat bin/windows/spring-mvc-petstore-server.bat bin/windows/springboot-petstore-server.bat bin/windows/swift-petstore.bat bin/windows/tizen-petstore.bat bin/windows/typescript-angular.bat bin/windows/typescript-angular2.bat bin/windows/typescript-fetch.bat bin/windows/typescript-node-with-npm.bat bin/windows/typescript-node.bat * Revert "cleanup" This reverts commit c752ba85d8a795ebcaf902a0eb06ab0c5755d128. * Revert "re-create bin folder" This reverts commit 8a6d41314784a2ae5ce29ae54d7db1ebec418751. Conflicts: bin/windows/spring-mvc-petstore-j8-async-server.bat bin/windows/spring-mvc-petstore-server.bat bin/windows/springboot-petstore-server.bat * Revert "re-create bin folder" This reverts commit 8a6d41314784a2ae5ce29ae54d7db1ebec418751. Conflicts: bin/windows/spring-mvc-petstore-j8-async-server.bat bin/windows/spring-mvc-petstore-server.bat bin/windows/springboot-petstore-server.bat * re-create bin from master * Revert "re-create bin from master" This reverts commit d4b5c9aac54d62dfb3790c1bf2829472be2ec8fd. * Revert "Revert "re-create bin folder"" This reverts commit 4369b35dbe9d21f8a93e7632fd92a9a760256db5. * Revert "re-create bin folder" This reverts commit 8a6d41314784a2ae5ce29ae54d7db1ebec418751. * Revert "temporary solution for pattern - move to AbstractJavaCodegen #2549" This reverts commit 82df5e657f31303bcb7d38f1dc013183d3509da2, reversing changes made to 65e87f23a6804a0d5c0926c916a9cd6866e7fee0. * correct @Path to re-activate Swagger support # * change sourceFolder to default * re-activate unittest generator + support gzip switch #2017 * add switch to support Spring Boot + integration tests * add cxf client generator, rename cxf server generator #2017 * add interfaces for language feature support #4003 * add comments #2017 * correct reference to context.xml.mustache #4003 * use dynamic sourceFolder path #2017 * replace tabs with spaces #4003 * use hard-coded sourceFolder #4003 * rename language for backwards compatibility * cleanup todo comment #4003 * move convertPropertyToBooleanAndWriteBack to DefaultCodegen #4003 * change reference to beanValidation.mustache to local copy for cxf * cleanup client-side beanvalidation (currently not working in CXF) * add support for tags #4003 * fix instantiiation of method parameters * move commonValidationFeature from bus to endpoint #4003
This commit is contained in:
@@ -3330,4 +3330,23 @@ public class DefaultCodegen {
|
||||
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* reads propertyKey from additionalProperties, converts it to a boolean and
|
||||
* writes it back to additionalProperties to be usable as a boolean in
|
||||
* mustache files.
|
||||
*
|
||||
* @param propertyKey
|
||||
* @return property value as boolean
|
||||
*/
|
||||
public boolean convertPropertyToBooleanAndWriteBack(String propertyKey) {
|
||||
boolean booleanValue = false;
|
||||
if (additionalProperties.containsKey(propertyKey)) {
|
||||
booleanValue = Boolean.valueOf(additionalProperties.get(propertyKey).toString());
|
||||
// write back as boolean
|
||||
additionalProperties.put(propertyKey, booleanValue);
|
||||
}
|
||||
|
||||
return booleanValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -935,4 +935,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toRegularExpression(String pattern) {
|
||||
return escapeText(pattern);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.languages.features.CXFFeatures;
|
||||
import io.swagger.codegen.languages.features.LoggingFeatures;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
public class JavaCXFClientCodegen extends AbstractJavaCodegen implements CXFFeatures
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaCXFClientCodegen.class);
|
||||
|
||||
/**
|
||||
* Name of the sub-directory in "src/main/resource" where to find the
|
||||
* Mustache template for the JAX-RS Codegen.
|
||||
*/
|
||||
protected static final String JAXRS_TEMPLATE_DIRECTORY_NAME = "JavaJaxRS";
|
||||
|
||||
protected boolean useBeanValidation = false;
|
||||
|
||||
protected boolean useGzipFeature = false;
|
||||
|
||||
protected boolean useLoggingFeature = false;
|
||||
|
||||
protected boolean useBeanValidationFeature = false;
|
||||
|
||||
|
||||
public JavaCXFClientCodegen()
|
||||
{
|
||||
super();
|
||||
|
||||
supportsInheritance = true;
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-client";
|
||||
dateLibrary = "legacy"; //TODO: add joda support to all jax-rs
|
||||
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
outputFolder = "generated-code/JavaJaxRS-CXF";
|
||||
|
||||
// clear model and api doc template as this codegen
|
||||
// does not support auto-generated markdown doc at the moment
|
||||
//TODO: add doc templates
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
|
||||
|
||||
typeMapping.put("date", "LocalDate");
|
||||
typeMapping.put("DateTime", "javax.xml.datatype.XMLGregorianCalendar"); // Map DateTime fields to Java standart class 'XMLGregorianCalendar'
|
||||
|
||||
importMapping.put("LocalDate", "org.joda.time.LocalDate");
|
||||
|
||||
embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Use Gzip Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION_FEATURE, "Use BeanValidation Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE, "Use Logging Feature"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
|
||||
this.setUseBeanValidation(useBeanValidationProp);
|
||||
}
|
||||
|
||||
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
|
||||
this.setUseLoggingFeature(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE));
|
||||
|
||||
boolean useBeanValidationFeature = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION_FEATURE);
|
||||
this.setUseBeanValidationFeature(useBeanValidationFeature);
|
||||
if (useBeanValidationFeature) {
|
||||
LOGGER.info("make sure your client supports Bean Validation 1.1");
|
||||
}
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf-client";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag()
|
||||
{
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
model.imports.remove("ApiModelProperty");
|
||||
model.imports.remove("ApiModel");
|
||||
model.imports.remove("JsonSerialize");
|
||||
model.imports.remove("ToStringSerializer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp()
|
||||
{
|
||||
return "Generates a Java JAXRS Client based on Apache CXF framework.";
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature) {
|
||||
this.useGzipFeature = useGzipFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseLoggingFeature(boolean useLoggingFeature) {
|
||||
this.useLoggingFeature = useLoggingFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseBeanValidationFeature(boolean useBeanValidationFeature) {
|
||||
this.useBeanValidationFeature = useBeanValidationFeature;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,23 +5,51 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.languages.features.CXFServerFeatures;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen implements CXFServerFeatures
|
||||
{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaCXFServerCodegen.class);
|
||||
|
||||
protected boolean useBeanValidation = false;
|
||||
|
||||
protected boolean generateSpringApplication = false;
|
||||
|
||||
protected boolean useSwaggerFeature = false;
|
||||
|
||||
protected boolean useWadlFeature = false;
|
||||
|
||||
protected boolean useMultipartFeature = false;
|
||||
|
||||
protected boolean useGzipFeature = false;
|
||||
|
||||
protected boolean useLoggingFeature = false;
|
||||
|
||||
protected boolean useBeanValidationFeature = false;
|
||||
|
||||
protected boolean generateSpringBootApplication= false;
|
||||
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
super();
|
||||
sourceFolder = "gen" + File.separator + "java";
|
||||
|
||||
supportsInheritance = true;
|
||||
|
||||
artifactId = "swagger-cxf-server";
|
||||
|
||||
outputFolder = "generated-code/JavaJaxRS-CXF";
|
||||
apiTestTemplateFiles.clear(); // TODO: add test template
|
||||
|
||||
//TODO add auto-generated pom.xml for maven
|
||||
//apiTemplateFiles.put("pom.mustache", "pom.xml");
|
||||
|
||||
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
|
||||
// clear model and api doc template as this codegen
|
||||
// does not support auto-generated markdown doc at the moment
|
||||
//TODO: add doc templates
|
||||
@@ -36,14 +64,86 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
|
||||
embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";
|
||||
|
||||
}
|
||||
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_SWAGGER_FEATURE, "Use Swagger Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_WADL_FEATURE, "Use WADL Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_MULTIPART_FEATURE, "Use Multipart Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Use Gzip Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION_FEATURE, "Use BeanValidation Feature"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_LOGGING_FEATURE, "Use Logging Feature"));
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(GENERATE_SPRING_BOOT_APPLICATION, "Generate Spring Boot application"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
|
||||
this.setUseBeanValidation(useBeanValidationProp);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(GENERATE_SPRING_APPLICATION)) {
|
||||
this.setGenerateSpringApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_APPLICATION));
|
||||
|
||||
this.setUseSwaggerFeature(convertPropertyToBooleanAndWriteBack(USE_SWAGGER_FEATURE));
|
||||
this.setUseWadlFeature(convertPropertyToBooleanAndWriteBack(USE_WADL_FEATURE));
|
||||
this.setUseMultipartFeature(convertPropertyToBooleanAndWriteBack(USE_MULTIPART_FEATURE));
|
||||
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
|
||||
this.setUseLoggingFeature(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE));
|
||||
|
||||
boolean useBeanValidationFeature = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION_FEATURE);
|
||||
this.setUseBeanValidationFeature(useBeanValidationFeature);
|
||||
if (useBeanValidationFeature) {
|
||||
LOGGER.info("make sure your target server supports Bean Validation 1.1");
|
||||
}
|
||||
|
||||
this.setGenerateSpringBootApplication(convertPropertyToBooleanAndWriteBack(GENERATE_SPRING_BOOT_APPLICATION));
|
||||
}
|
||||
|
||||
|
||||
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("server/pom.mustache", "", "pom.xml"));
|
||||
|
||||
if (this.generateSpringApplication) {
|
||||
writeOptional(outputFolder, new SupportingFile("server/readme.md", "", "readme.md"));
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("server/ApplicationContext.xml.mustache",
|
||||
("src/main/resources"), "ApplicationContext.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("server/web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("server/context.xml.mustache",
|
||||
("src/main/webapp/WEB-INF"), "context.xml"));
|
||||
|
||||
// Jboss
|
||||
writeOptional(outputFolder, new SupportingFile("server/jboss-web.xml.mustache",
|
||||
("src/main/webapp/WEB-INF"), "jboss-web.xml"));
|
||||
|
||||
// Spring Boot
|
||||
if (this.generateSpringBootApplication) {
|
||||
writeOptional(outputFolder, new SupportingFile("server/SpringBootApplication.mustache",
|
||||
(testFolder + '/' + apiPackage).replace(".", "/"), "SpringBootApplication.java"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
@@ -65,4 +165,46 @@ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public void setUseSwaggerFeature(boolean useSwaggerFeature) {
|
||||
this.useSwaggerFeature = useSwaggerFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseWadlFeature(boolean useWadlFeature) {
|
||||
this.useWadlFeature = useWadlFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseMultipartFeature(boolean useMultipartFeature) {
|
||||
this.useMultipartFeature = useMultipartFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature) {
|
||||
this.useGzipFeature = useGzipFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseLoggingFeature(boolean useLoggingFeature) {
|
||||
this.useLoggingFeature = useLoggingFeature;
|
||||
}
|
||||
|
||||
|
||||
public void setUseBeanValidationFeature(boolean useBeanValidationFeature) {
|
||||
this.useBeanValidationFeature = useBeanValidationFeature;
|
||||
}
|
||||
|
||||
public void setGenerateSpringBootApplication(boolean generateSpringBootApplication) {
|
||||
this.generateSpringBootApplication = generateSpringBootApplication;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.codegen.languages.features.BeanValidationFeatures;
|
||||
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -9,7 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
public class JavaClientCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
@SuppressWarnings("hiding")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
|
||||
@@ -24,6 +26,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
protected boolean useRxJava = false;
|
||||
protected boolean parcelableModel = false;
|
||||
protected boolean supportJava6= false;
|
||||
protected boolean useBeanValidation = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
@@ -37,6 +40,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
|
||||
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
|
||||
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0. Enable Java6 support using '-DsupportJava6=true'.");
|
||||
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.16.0. JSON processing: Jackson 2.7.0");
|
||||
@@ -81,6 +85,14 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
// put the boolean value back to PARCELABLE_MODEL in additionalProperties
|
||||
additionalProperties.put(PARCELABLE_MODEL, parcelableModel);
|
||||
|
||||
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
|
||||
boolean useBeanValidationProp = Boolean.valueOf(additionalProperties.get(USE_BEANVALIDATION).toString());
|
||||
this.setUseBeanValidation(useBeanValidationProp);
|
||||
|
||||
// write back as boolean
|
||||
additionalProperties.put(USE_BEANVALIDATION, useBeanValidationProp);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
|
||||
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
|
||||
@@ -184,7 +196,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
operation.returnType = "Void";
|
||||
}
|
||||
if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/"))
|
||||
operation.path = operation.path.substring(1);
|
||||
operation.path = operation.path.substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,7 +244,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
public void setUseRxJava(boolean useRxJava) {
|
||||
this.useRxJava = useRxJava;
|
||||
}
|
||||
@@ -245,4 +257,8 @@ public class JavaClientCodegen extends AbstractJavaCodegen {
|
||||
this.supportJava6 = value;
|
||||
}
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation) {
|
||||
this.useBeanValidation = useBeanValidation;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface BeanValidationExtendedFeatures {
|
||||
|
||||
// Language (implementing Client/Server) supports automatic BeanValidation (1.1)
|
||||
public static final String USE_BEANVALIDATION_FEATURE = "useBeanValidationFeature";
|
||||
|
||||
public void setUseBeanValidationFeature(boolean useBeanValidationFeature);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface BeanValidationFeatures {
|
||||
|
||||
// Language supports generating BeanValidation-Annotations
|
||||
public static final String USE_BEANVALIDATION = "useBeanValidation";
|
||||
|
||||
public void setUseBeanValidation(boolean useBeanValidation);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
/**
|
||||
* Features supported by CXF 3 (client + server)
|
||||
*
|
||||
*/
|
||||
public interface CXFFeatures extends LoggingFeatures, GzipFeatures, BeanValidationFeatures, BeanValidationExtendedFeatures {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
/**
|
||||
* Features supported by CXF 3 server
|
||||
*
|
||||
*/
|
||||
public interface CXFServerFeatures extends CXFFeatures, SwaggerFeatures, SpringFeatures {
|
||||
|
||||
public static final String USE_WADL_FEATURE = "useWadlFeature";
|
||||
|
||||
public static final String USE_MULTIPART_FEATURE = "useMultipartFeature";
|
||||
|
||||
public void setUseWadlFeature(boolean useWadlFeature);
|
||||
|
||||
public void setUseMultipartFeature(boolean useMultipartFeature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface GzipFeatures {
|
||||
|
||||
public static final String USE_GZIP_FEATURE = "useGzipFeature";
|
||||
|
||||
public void setUseGzipFeature(boolean useGzipFeature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface LoggingFeatures extends BeanValidationFeatures {
|
||||
|
||||
public static final String USE_LOGGING_FEATURE = "useLoggingFeature";
|
||||
|
||||
public void setUseLoggingFeature(boolean useLoggingFeature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface SpringFeatures extends BeanValidationFeatures {
|
||||
|
||||
public static final String GENERATE_SPRING_APPLICATION = "generateSpringApplication";
|
||||
|
||||
public static final String GENERATE_SPRING_BOOT_APPLICATION = "generateSpringBootApplication";
|
||||
|
||||
public void setGenerateSpringApplication(boolean useGenerateSpringApplication);
|
||||
|
||||
public void setGenerateSpringBootApplication(boolean generateSpringBootApplication);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.swagger.codegen.languages.features;
|
||||
|
||||
public interface SwaggerFeatures extends CXFFeatures {
|
||||
|
||||
public static final String USE_SWAGGER_FEATURE = "useSwaggerFeature";
|
||||
|
||||
public void setUseSwaggerFeature(boolean useSwaggerFeature);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user