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);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
{{#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}}
|
||||
@@ -131,6 +131,15 @@
|
||||
<version>${jodatime-version}</version>
|
||||
</dependency>
|
||||
{{/java8}}
|
||||
{{#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}}
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
@@ -152,4 +161,4 @@
|
||||
<junit-version>4.12</junit-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
</project>
|
||||
@@ -18,6 +18,9 @@ import java.io.Serializable;
|
||||
import android.os.Parcelable;
|
||||
import android.os.Parcel;
|
||||
{{/parcelableModel}}
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
@@ -66,7 +66,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
|
||||
{{#vendorExtensions.extraAnnotation}}
|
||||
{{{vendorExtensions.extraAnnotation}}}
|
||||
{{/vendorExtensions.extraAnnotation}}
|
||||
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
{{#vendorExtensions.extraAnnotation}}
|
||||
{{vendorExtensions.extraAnnotation}}
|
||||
{{/vendorExtensions.extraAnnotation}}
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
|
||||
@@ -180,7 +180,6 @@
|
||||
<artifactId>migbase64</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
{{#supportJava6}}
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@@ -194,7 +193,15 @@
|
||||
<version>${commons_io_version}</version>
|
||||
</dependency>
|
||||
{{/supportJava6}}
|
||||
|
||||
{{#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}}
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -12,15 +12,24 @@ import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.cxf.jaxrs.ext.multipart.*;
|
||||
|
||||
@Path("{{contextPath}}")
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
@Path("/")
|
||||
@Api(value = "/", description = "{{description}}")
|
||||
public interface {{classname}} {
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
|
||||
@{{httpMethod}}
|
||||
{{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}}
|
||||
{{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}}
|
||||
{{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}}
|
||||
Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}});
|
||||
@ApiOperation(value = "{{summary}}", tags={ {{#vendorExtensions.x-tags}}"{{tag}}"{{#hasMore}}, {{/hasMore}}{{/vendorExtensions.x-tags}} })
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package {{package}}.impl;
|
||||
|
||||
import {{package}}.*;
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.apache.cxf.jaxrs.model.wadl.Description;
|
||||
import org.apache.cxf.jaxrs.model.wadl.DocTarget;
|
||||
|
||||
import org.apache.cxf.jaxrs.ext.multipart.*;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
|
||||
{{#description}}
|
||||
{{/description}}
|
||||
public class {{classname}}ServiceImpl implements {{classname}} {
|
||||
{{#operations}}
|
||||
{{#operation}}
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}}({{#allParams}}{{>queryParamsImpl}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
|
||||
// TODO: Implement...
|
||||
|
||||
{{#returnType}}return null;{{/returnType}}
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
{{>licenseInfo}}
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
|
||||
import org.apache.cxf.jaxrs.client.ClientConfiguration;
|
||||
import org.apache.cxf.jaxrs.client.WebClient;
|
||||
{{#useGzipFeature}}
|
||||
import org.apache.cxf.transport.common.gzip.GZIPInInterceptor;
|
||||
import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;
|
||||
{{/useGzipFeature}}
|
||||
|
||||
{{#useLoggingFeature}}
|
||||
import org.apache.cxf.interceptor.LoggingOutInterceptor;
|
||||
{{/useLoggingFeature}}
|
||||
|
||||
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
|
||||
|
||||
{{^fullJavaUtil}}
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
{{/fullJavaUtil}}
|
||||
|
||||
{{#generateSpringBootApplication}}
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
{{/generateSpringBootApplication}}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* API tests for {{classname}}
|
||||
*/
|
||||
{{#generateSpringBootApplication}}
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = SpringBootApplication.class)
|
||||
@WebAppConfiguration
|
||||
@IntegrationTest("server.port=0")
|
||||
{{/generateSpringBootApplication}}
|
||||
public class {{classname}}Test {
|
||||
|
||||
{{#generateSpringBootApplication}}
|
||||
@Value("${local.server.port}")
|
||||
private int serverPort;
|
||||
{{/generateSpringBootApplication}}
|
||||
|
||||
private {{classname}} api;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
JacksonJsonProvider provider = new JacksonJsonProvider();
|
||||
List providers = new ArrayList();
|
||||
providers.add(provider);
|
||||
|
||||
{{#generateSpringBootApplication}}
|
||||
api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services/services", {{classname}}.class, providers);
|
||||
{{/generateSpringBootApplication}}
|
||||
{{^generateSpringBootApplication}}
|
||||
api = JAXRSClientFactory.create("{{basePath}}", {{classname}}.class, providers);
|
||||
{{/generateSpringBootApplication}}
|
||||
org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
|
||||
|
||||
ClientConfiguration config = WebClient.getConfig(client);
|
||||
{{#useGzipFeature}}
|
||||
// Example for using Gzipping
|
||||
GZIPOutInterceptor gzipOutInterceptor = new GZIPOutInterceptor();
|
||||
// use Gzipping for first request sent to server
|
||||
//gzipOutInterceptor.setForce(true);
|
||||
config.getOutInterceptors().add(gzipOutInterceptor);
|
||||
|
||||
config.getInInterceptors().add(new GZIPInInterceptor());
|
||||
{{/useGzipFeature}}
|
||||
{{#useLoggingFeature}}
|
||||
LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor();
|
||||
config.getOutInterceptors().add(loggingOutInterceptor);
|
||||
{{/useLoggingFeature}}
|
||||
}
|
||||
|
||||
{{#operations}}{{#operation}}
|
||||
/**
|
||||
* {{summary}}
|
||||
*
|
||||
* {{notes}}
|
||||
*
|
||||
* @throws ApiException
|
||||
* if the Api call fails
|
||||
*/
|
||||
@Test
|
||||
public void {{operationId}}Test() {
|
||||
{{#allParams}}
|
||||
{{{dataType}}} {{paramName}} = null;
|
||||
{{/allParams}}
|
||||
// {{#returnType}}{{{returnType}}} response = {{/returnType}}api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||
|
||||
// TODO: test validations
|
||||
}
|
||||
{{/operation}}{{/operations}}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
{{#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}}
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* {{{appName}}}
|
||||
* {{{appDescription}}}
|
||||
*
|
||||
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
|
||||
* {{#infoEmail}}Contact: {{{infoEmail}}}{{/infoEmail}}
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@@ -2,6 +2,9 @@ package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
{{#useBeanValidation}}
|
||||
import javax.validation.constraints.*;
|
||||
{{/useBeanValidation}}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
@@ -7,10 +8,13 @@ import javax.xml.bind.annotation.XmlEnum;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
{{#hasVars}} @XmlType(name = "{{classname}}", propOrder =
|
||||
{ {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}}
|
||||
{ {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}}
|
||||
}){{/hasVars}}
|
||||
{{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}}
|
||||
{{^parent}}@XmlRootElement(name="{{classname}}"){{/parent}}
|
||||
{{#description}}
|
||||
@ApiModel(description="{{{description}}}")
|
||||
{{/description}}
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
|
||||
@@ -19,16 +23,29 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{>enumClass}}{{/items}}{{/items.isEnum}}
|
||||
|
||||
@XmlElement(name="{{baseName}}")
|
||||
@ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}")
|
||||
private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
/**{{#description}}
|
||||
* {{{description}}}{{/description}}{{#minimum}}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
{{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}}
|
||||
public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
/**
|
||||
{{#description}}
|
||||
* {{{description}}}
|
||||
{{/description}}
|
||||
{{^description}}
|
||||
* Get {{name}}
|
||||
{{/description}}
|
||||
{{#minimum}}
|
||||
* minimum: {{minimum}}
|
||||
{{/minimum}}
|
||||
{{#maximum}}
|
||||
* maximum: {{maximum}}
|
||||
{{/maximum}}
|
||||
* @return {{name}}
|
||||
**/
|
||||
{{#vendorExtensions.extraAnnotation}}
|
||||
{{vendorExtensions.extraAnnotation}}
|
||||
{{/vendorExtensions.extraAnnotation}}
|
||||
{{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}} public {{{datatypeWithEnum}}} {{getter}}() {
|
||||
return {{name}};
|
||||
}
|
||||
public void {{setter}}({{{datatypeWithEnum}}} {{name}}) {
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>{{serverPort}}</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin-->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/gen/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jaxrs</artifactId>
|
||||
<scope>compile</scope>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/useBeanValidation}}
|
||||
<!-- CXF Client -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-client</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- CXF server -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-service-description</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-ws-policy</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-wsdl</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
{{#useBeanValidationFeature}}
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>5.2.2.Final</version>
|
||||
</dependency>
|
||||
{{/useBeanValidationFeature}}
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.9</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.22.2</jersey2-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<logback-version>1.1.7</logback-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
{{#useBeanValidation}}
|
||||
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
|
||||
{{/useBeanValidation}}
|
||||
<cxf-version>3.1.6</cxf-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -1 +1 @@
|
||||
{{#isQueryParam}}@QueryParam("{{baseName}}") {{{dataType}}} {{paramName}}{{/isQueryParam}}
|
||||
{{#isQueryParam}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidation}}{{/useBeanValidation}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
|
||||
@@ -0,0 +1 @@
|
||||
{{#isQueryParam}}{{{dataType}}} {{paramName}}{{/isQueryParam}}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cxf="http://cxf.apache.org/core"
|
||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||
xmlns:jee="http://www.springframework.org/schema/jee"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
|
||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
|
||||
|
||||
|
||||
|
||||
<import resource="classpath:META-INF/cxf/cxf.xml" />
|
||||
|
||||
<!-- JAXRS providers -->
|
||||
<bean id="jsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
|
||||
|
||||
{{#useMultipartFeature}}
|
||||
<bean id="multipartProvider" class="org.apache.cxf.jaxrs.provider.MultipartProvider" />
|
||||
{{/useMultipartFeature}}
|
||||
|
||||
<!-- Controller -->
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
<bean id="{{classname}}" class="{{package}}.impl.{{classname}}ServiceImpl" />
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
||||
{{#useSwaggerFeature}}
|
||||
<!-- CXF Swagger2Feature -->
|
||||
{{! http://cxf.apache.org/docs/swagger2feature.html }}
|
||||
<bean id="swagger2Feature" class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
|
||||
<!--property name="basePath" value="/"/>
|
||||
<property name="contact" value="${swagger.contact}" />
|
||||
<property name="title" value="${swagger.title}" />
|
||||
<property name="version" value="${swagger.version}" />
|
||||
<property name="description" value="${swagger.description}" />
|
||||
<property name="license" value="${swagger.license}" />
|
||||
<property name="licenseUrl" value="${swagger.licenseUrl}" /-->
|
||||
</bean>
|
||||
{{/useSwaggerFeature}}
|
||||
|
||||
<cxf:bus>
|
||||
<cxf:inInterceptors>
|
||||
{{#useGzipFeature}}
|
||||
<ref bean="GZIPInInterceptor"/>
|
||||
{{/useGzipFeature}}
|
||||
{{#useBeanValidationFeature}}
|
||||
<!-- BeanValidation 1.1 for CXF -->
|
||||
<ref bean="validationInInterceptor" />
|
||||
{{/useBeanValidationFeature}}
|
||||
</cxf:inInterceptors>
|
||||
<cxf:outInterceptors>
|
||||
{{#useGzipFeature}}
|
||||
<ref bean="GZIPOutInterceptor"/>
|
||||
{{/useGzipFeature}}
|
||||
{{#useBeanValidationFeature}}
|
||||
<!-- BeanValidation 1.1 for CXF -->
|
||||
<ref bean="validationOutInterceptor" />
|
||||
{{/useBeanValidationFeature}}
|
||||
</cxf:outInterceptors>
|
||||
<cxf:features>
|
||||
{{#useLoggingFeature}}
|
||||
<cxf:logging />
|
||||
{{/useLoggingFeature}}
|
||||
{{#useGzipFeature}}
|
||||
<ref bean="compressGZIPFeature"/>
|
||||
{{/useGzipFeature}}
|
||||
</cxf:features>
|
||||
<cxf:properties>
|
||||
<entry key="javax.ws.rs.ext.ExceptionMapper" value-ref="exceptionMapper"/>
|
||||
</cxf:properties>
|
||||
</cxf:bus>
|
||||
|
||||
{{#useWadlFeature}}
|
||||
<bean id="wadlGenerator"
|
||||
class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
|
||||
<property name="linkJsonToXmlSchema" value="true" />
|
||||
</bean>
|
||||
{{/useWadlFeature}}
|
||||
|
||||
{{#useGzipFeature}}
|
||||
<bean id="GZIPInInterceptor" class="org.apache.cxf.transport.common.gzip.GZIPInInterceptor"/>
|
||||
<bean id="GZIPOutInterceptor" class="org.apache.cxf.transport.common.gzip.GZIPOutInterceptor" >
|
||||
<!--property name="force" value="true" /-->
|
||||
<!--property name="threshold" value="0" /-->
|
||||
</bean>
|
||||
|
||||
<bean id="compressGZIPFeature" class="org.apache.cxf.transport.common.gzip.GZIPFeature"/>
|
||||
{{/useGzipFeature}}
|
||||
|
||||
{{#useBeanValidationFeature}}
|
||||
<bean id="commonValidationFeature" class="org.apache.cxf.validation.BeanValidationFeature"/>
|
||||
<bean id="exceptionMapper" class="org.apache.cxf.jaxrs.validation.ValidationExceptionMapper"/>
|
||||
<bean id="validationProvider" class="org.apache.cxf.validation.BeanValidationProvider" />
|
||||
|
||||
<bean id="validationInInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationInInterceptor">
|
||||
<property name="provider" ref="validationProvider" />
|
||||
</bean>
|
||||
|
||||
<bean id="validationOutInterceptor" class="org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor">
|
||||
<property name="provider" ref="validationProvider" />
|
||||
</bean>
|
||||
{{/useBeanValidationFeature}}
|
||||
{{^useBeanValidationFeature}}
|
||||
<bean id="exceptionMapper" class="org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper">
|
||||
<property name="addMessageToResponse" value="true" />
|
||||
</bean>
|
||||
{{/useBeanValidationFeature}}
|
||||
|
||||
<!-- REST server -->
|
||||
<jaxrs:server id="restServer" address="/services">
|
||||
<jaxrs:serviceBeans>
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
<ref bean="{{classname}}" />
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<ref bean="jsonProvider" />
|
||||
{{#useMultipartFeature}}
|
||||
<ref bean="multipartProvider" />
|
||||
{{/useMultipartFeature}}
|
||||
{{#useWadlFeature}}
|
||||
<ref bean="wadlGenerator" />
|
||||
{{/useWadlFeature}}
|
||||
</jaxrs:providers>
|
||||
<jaxrs:features>
|
||||
{{#useSwaggerFeature}}
|
||||
<ref bean="swagger2Feature" />
|
||||
{{/useSwaggerFeature}}
|
||||
{{#useBeanValidationFeature}}
|
||||
<ref bean="commonValidationFeature" />
|
||||
{{/useBeanValidationFeature}}
|
||||
</jaxrs:features>
|
||||
</jaxrs:server>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,23 @@
|
||||
package {{apiPackage}};
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
@ImportResource({"classpath:/ApplicationContext.xml"})
|
||||
@EnableAutoConfiguration
|
||||
public class SpringBootApplication extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(SpringBootApplication.class);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootApplication.class, args);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cxf="http://cxf.apache.org/core"
|
||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||
xmlns:jee="http://www.springframework.org/schema/jee"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
|
||||
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
|
||||
|
||||
|
||||
|
||||
<import resource="classpath:/ApplicationContext.xml" />
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.3//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
|
||||
<jboss-web>
|
||||
|
||||
<context-root>swagger-cxf-server</context-root>
|
||||
|
||||
</jboss-web>
|
||||
@@ -0,0 +1,231 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>{{groupId}}</groupId>
|
||||
<artifactId>{{artifactId}}</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>{{artifactId}}</name>
|
||||
<version>{{artifactVersion}}</version>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--plugin>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>${jetty-version}</version>
|
||||
<configuration>
|
||||
<webApp>
|
||||
<contextPath>/</contextPath>
|
||||
</webApp>
|
||||
<webAppSourceDirectory>target/${project.artifactId}-${project.version}</webAppSourceDirectory>
|
||||
<stopPort>8079</stopPort>
|
||||
<stopKey>stopit</stopKey>
|
||||
<httpConnector>
|
||||
<port>{{serverPort}}</port>
|
||||
<idleTimeout>60000</idleTimeout>
|
||||
</httpConnector>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>start-jetty</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<goals>
|
||||
<goal>start</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<scanIntervalSeconds>0</scanIntervalSeconds>
|
||||
<daemon>true</daemon>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>stop-jetty</id>
|
||||
<phase>post-integration-test</phase>
|
||||
<goals>
|
||||
<goal>stop</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin-->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.9.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/gen/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- build WAR file -->
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>true</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-jaxrs</artifactId>
|
||||
<scope>compile</scope>
|
||||
<version>${swagger-core-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
{{#useBeanValidation}}
|
||||
<!-- Bean Validation API support -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${beanvalidation-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/useBeanValidation}}
|
||||
<!-- CXF Client -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-client</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- CXF server -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-service-description</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-ws-policy</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-wsdl</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
{{#generateSpringApplication}}
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring-version}</version>
|
||||
</dependency>
|
||||
{{/generateSpringApplication}}
|
||||
{{#generateSpringBootApplication}}
|
||||
<!-- Spring Boot dependencies für Integrationstests -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<version>${spring.boot-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<version>${spring.boot-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
|
||||
<version>${cxf-version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
{{/generateSpringBootApplication}}
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<properties>
|
||||
<java.version>{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}</java.version>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||
<swagger-core-version>1.5.9</swagger-core-version>
|
||||
<jetty-version>9.2.9.v20150224</jetty-version>
|
||||
<jersey2-version>2.22.2</jersey2-version>
|
||||
<junit-version>4.12</junit-version>
|
||||
<logback-version>1.1.7</logback-version>
|
||||
<servlet-api-version>2.5</servlet-api-version>
|
||||
{{#useBeanValidation}}
|
||||
<beanvalidation-version>1.1.0.Final</beanvalidation-version>
|
||||
{{/useBeanValidation}}
|
||||
{{#generateSpringApplication}}
|
||||
<spring-version>4.2.5.RELEASE</spring-version>
|
||||
{{/generateSpringApplication}}
|
||||
{{#generateSpringBootApplication}}
|
||||
<spring.boot-version>1.3.3.RELEASE</spring.boot-version>
|
||||
{{/generateSpringBootApplication}}
|
||||
<cxf-version>3.1.7</cxf-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
# JAX-RS CXF 3 server application
|
||||
|
||||
## Supported features
|
||||
* Bean-Validation-API support
|
||||
* Spring-configuration of Swagger, WADL and Endpoints
|
||||
* Swagger-API is accessible (CXF3 Swagger2Feature)
|
||||
* WADL is accessible (CXF WADL-Generator)
|
||||
* Unit-tests include Gzip-Interceptors for demonstration
|
||||
|
||||
|
||||
## Urls to access the REST API
|
||||
|
||||
* Available services listing
|
||||
http://localhost:8080/swagger-cxf-server/rest/services/
|
||||
|
||||
* Swagger API
|
||||
http://localhost:8080/swagger-cxf-server/rest/services/swagger.json
|
||||
|
||||
* CXF WADL
|
||||
http://localhost:8080/swagger-cxf-server/rest/services?_wadl
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
|
||||
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>WEB-INF/context.xml</param-value>
|
||||
</context-param>
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<servlet>
|
||||
<display-name>CXF Service Servlet</display-name>
|
||||
<servlet-name>CXFServiceServlet</servlet-name>
|
||||
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>CXFServiceServlet</servlet-name>
|
||||
<url-pattern>/rest/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
@@ -12,6 +12,7 @@ io.swagger.codegen.languages.GoClientCodegen
|
||||
io.swagger.codegen.languages.GroovyClientCodegen
|
||||
io.swagger.codegen.languages.JavaClientCodegen
|
||||
io.swagger.codegen.languages.JavaJerseyServerCodegen
|
||||
io.swagger.codegen.languages.JavaCXFClientCodegen
|
||||
io.swagger.codegen.languages.JavaCXFServerCodegen
|
||||
io.swagger.codegen.languages.JavaResteasyServerCodegen
|
||||
io.swagger.codegen.languages.JavaJAXRSSpecServerCodegen
|
||||
|
||||
@@ -58,6 +58,8 @@ public class JavaClientOptionsTest extends AbstractOptionsTest {
|
||||
times = 1;
|
||||
//clientCodegen.setSupportJava6(Boolean.valueOf(JavaOptionsProvider.SUPPORT_JAVA6));
|
||||
//times = 1;
|
||||
clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaOptionsProvider.USE_BEANVALIDATION));
|
||||
times = 1;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.swagger.codegen.jaxrs;
|
||||
|
||||
import io.swagger.codegen.AbstractOptionsTest;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.languages.JavaCXFServerCodegen;
|
||||
import io.swagger.codegen.options.JavaCXFServerOptionsProvider;
|
||||
import io.swagger.codegen.options.OptionsProvider;
|
||||
import mockit.Expectations;
|
||||
import mockit.Tested;
|
||||
|
||||
public class JaxrsCXFServerOptionsTest extends AbstractOptionsTest {
|
||||
|
||||
@Tested
|
||||
private JavaCXFServerCodegen clientCodegen;
|
||||
|
||||
public JaxrsCXFServerOptionsTest() {
|
||||
super(new JavaCXFServerOptionsProvider());
|
||||
}
|
||||
|
||||
protected JaxrsCXFServerOptionsTest(OptionsProvider optionsProvider) {
|
||||
super(optionsProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CodegenConfig getCodegenConfig() {
|
||||
return clientCodegen;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setExpectations() {
|
||||
new Expectations(clientCodegen) {{
|
||||
clientCodegen.setModelPackage(JavaCXFServerOptionsProvider.MODEL_PACKAGE_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setApiPackage(JavaCXFServerOptionsProvider.API_PACKAGE_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(JavaCXFServerOptionsProvider.SORT_PARAMS_VALUE));
|
||||
times = 1;
|
||||
clientCodegen.setInvokerPackage(JavaCXFServerOptionsProvider.INVOKER_PACKAGE_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setGroupId(JavaCXFServerOptionsProvider.GROUP_ID_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setArtifactId(JavaCXFServerOptionsProvider.ARTIFACT_ID_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setArtifactVersion(JavaCXFServerOptionsProvider.ARTIFACT_VERSION_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setSourceFolder(JavaCXFServerOptionsProvider.SOURCE_FOLDER_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setLocalVariablePrefix(JavaCXFServerOptionsProvider.LOCAL_PREFIX_VALUE);
|
||||
times = 1;
|
||||
clientCodegen.setSerializableModel(Boolean.valueOf(JavaCXFServerOptionsProvider.SERIALIZABLE_MODEL_VALUE));
|
||||
times = 1;
|
||||
clientCodegen.setFullJavaUtil(Boolean.valueOf(JavaCXFServerOptionsProvider.FULL_JAVA_UTIL_VALUE));
|
||||
times = 1;
|
||||
clientCodegen.setSerializeBigDecimalAsString(true);
|
||||
times = 1;
|
||||
|
||||
clientCodegen.setUseBeanValidation(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_BEANVALIDATION));
|
||||
times = 1;
|
||||
|
||||
clientCodegen.setGenerateSpringApplication(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_SWAGGER_FEATURE));
|
||||
times = 1;
|
||||
clientCodegen.setUseWadlFeature(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_WADL_FEATURE));
|
||||
times = 1;
|
||||
clientCodegen.setUseMultipartFeature(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_MULTIPART_FEATURE));
|
||||
times = 1;
|
||||
clientCodegen.setUseGzipFeature(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_GZIP_FEATURE));
|
||||
times = 1;
|
||||
clientCodegen.setUseLoggingFeature(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_LOGGING_FEATURE));
|
||||
times = 1;
|
||||
clientCodegen.setUseBeanValidationFeature(Boolean.valueOf(JavaCXFServerOptionsProvider.USE_BEANVALIDATION_FEATURE));
|
||||
times = 1;
|
||||
|
||||
clientCodegen.setGenerateSpringBootApplication(Boolean.valueOf(JavaCXFServerOptionsProvider.GENERATE_SPRING_BOOT_APPLICATION));
|
||||
times = 1;
|
||||
|
||||
|
||||
|
||||
}};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package io.swagger.codegen.options;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.languages.JavaCXFServerCodegen;
|
||||
|
||||
public class JavaCXFServerOptionsProvider extends JavaOptionsProvider {
|
||||
|
||||
public static final String GENERATE_SPRING_APPLICATION = "true";
|
||||
|
||||
public static final String USE_SWAGGER_FEATURE = "true";
|
||||
|
||||
public static final String USE_WADL_FEATURE = "true";
|
||||
|
||||
public static final String USE_MULTIPART_FEATURE = "true";
|
||||
|
||||
public static final String USE_GZIP_FEATURE = "true";
|
||||
|
||||
public static final String USE_LOGGING_FEATURE = "true";
|
||||
|
||||
public static final String USE_BEANVALIDATION_FEATURE = "true";
|
||||
|
||||
public static final String GENERATE_SPRING_BOOT_APPLICATION = "true";
|
||||
|
||||
public static final String IMPL_FOLDER_VALUE = "src/main/java";
|
||||
|
||||
@Override
|
||||
public boolean isServer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> createOptions() {
|
||||
|
||||
Map<String, String> parentOptions = super.createOptions();
|
||||
|
||||
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>()
|
||||
.putAll(parentOptions);
|
||||
|
||||
builder.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE);
|
||||
builder.put("title", "Test title");
|
||||
|
||||
builder.put(JavaCXFServerCodegen.USE_BEANVALIDATION, JavaOptionsProvider.USE_BEANVALIDATION);
|
||||
builder.put(JavaCXFServerCodegen.GENERATE_SPRING_APPLICATION, GENERATE_SPRING_APPLICATION);
|
||||
builder.put(JavaCXFServerCodegen.USE_SWAGGER_FEATURE, USE_SWAGGER_FEATURE);
|
||||
builder.put(JavaCXFServerCodegen.USE_WADL_FEATURE, USE_WADL_FEATURE);
|
||||
builder.put(JavaCXFServerCodegen.USE_MULTIPART_FEATURE, USE_MULTIPART_FEATURE);
|
||||
builder.put(JavaCXFServerCodegen.USE_GZIP_FEATURE, USE_GZIP_FEATURE);
|
||||
builder.put(JavaCXFServerCodegen.USE_LOGGING_FEATURE, USE_LOGGING_FEATURE);
|
||||
builder.put(JavaCXFServerCodegen.USE_BEANVALIDATION_FEATURE, USE_BEANVALIDATION_FEATURE);
|
||||
|
||||
builder.put(JavaCXFServerCodegen.GENERATE_SPRING_BOOT_APPLICATION, GENERATE_SPRING_BOOT_APPLICATION);
|
||||
|
||||
return builder.build();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ public class JavaClientOptionsProvider extends JavaOptionsProvider {
|
||||
options.put(JavaClientCodegen.USE_RX_JAVA, "false");
|
||||
options.put(JavaClientCodegen.PARCELABLE_MODEL, "false");
|
||||
options.put(JavaClientCodegen.SUPPORT_JAVA6, "false");
|
||||
options.put(JavaClientCodegen.USE_BEANVALIDATION, "false");
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class JavaOptionsProvider implements OptionsProvider {
|
||||
public static final String FULL_JAVA_UTIL_VALUE = "true";
|
||||
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||
//public static final String SUPPORT_JAVA6 = "true";
|
||||
public static final String USE_BEANVALIDATION = "false";
|
||||
|
||||
private ImmutableMap<String, String> options;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user