From ac328ccc59e2d4efed14ff3bde543962ad853c65 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sat, 2 Jul 2016 18:01:45 +0200 Subject: [PATCH 01/16] add pom-file to cxf including cxf-client #2017 --- .../languages/JavaCXFServerCodegen.java | 12 ++ .../main/resources/JavaJaxRS/cxf/pom.mustache | 139 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java index c9d558d51ab..9cfeba12726 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java @@ -8,6 +8,7 @@ import io.swagger.codegen.CodegenModel; import io.swagger.codegen.CodegenOperation; import io.swagger.codegen.CodegenProperty; +import io.swagger.codegen.SupportingFile; import io.swagger.models.Operation; public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen @@ -37,6 +38,17 @@ public JavaCXFServerCodegen() } + @Override + public void processOpts() + { + super.processOpts(); + + 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() { diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache new file mode 100644 index 00000000000..ca0d370b98a --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -0,0 +1,139 @@ + + 4.0.0 + {{groupId}} + {{artifactId}} + jar + {{artifactId}} + {{artifactVersion}} + + src/main/java + + + org.apache.maven.plugins + maven-war-plugin + 2.1.1 + + + maven-failsafe-plugin + 2.6 + + + + integration-test + verify + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty-version} + + + / + + target/${project.artifactId}-${project.version} + 8079 + stopit + + {{serverPort}} + 60000 + + + + + start-jetty + pre-integration-test + + start + + + 0 + true + + + + stop-jetty + post-integration-test + + stop + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.9.1 + + + add-source + generate-sources + + add-source + + + + src/gen/java + + + + + + + + + + io.swagger + swagger-jersey2-jaxrs + compile + ${swagger-core-version} + + + ch.qos.logback + logback-classic + ${logback-version} + compile + + + ch.qos.logback + logback-core + ${logback-version} + compile + + + junit + junit + ${junit-version} + test + + + org.apache.cxf + cxf-rt-rs-client + 3.1.6 + test + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + + + {{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}} + ${java.version} + ${java.version} + 1.5.9 + 9.2.9.v20150224 + 2.22.2 + 4.12 + 1.1.7 + 2.5 + UTF-8 + + From 4766b9bdf6c6efe79e317837ef85a96cf1e44d26 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sat, 2 Jul 2016 18:12:47 +0200 Subject: [PATCH 02/16] adapt pom sourceFolder in pom.mustache to gen/java #2017 --- .../src/main/resources/JavaJaxRS/cxf/pom.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index ca0d370b98a..43d02dec937 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -75,7 +75,7 @@ - src/gen/java + gen/java From ed5039b11d9e7dbbdb1de84eb41801006e04a9bc Mon Sep 17 00:00:00 2001 From: jfiala Date: Sat, 2 Jul 2016 18:53:00 +0200 Subject: [PATCH 03/16] add test templates for CXF #2017 --- .../languages/JavaCXFServerCodegen.java | 6 +- .../src/main/resources/Java/model.mustache | 2 +- .../resources/JavaJaxRS/cxf/api_test.mustache | 59 +++++++++++++++++++ .../JavaJaxRS/cxf/licenseInfo.mustache | 23 ++++++++ .../resources/JavaJaxRS/cxf/model.mustache | 1 + .../resources/JavaJaxRS/cxf/pojo.mustache | 9 +++ .../main/resources/JavaJaxRS/cxf/pom.mustache | 8 +++ 7 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/licenseInfo.mustache diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java index 9cfeba12726..b94f2d0c60d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java @@ -19,8 +19,7 @@ public JavaCXFServerCodegen() supportsInheritance = true; sourceFolder = "gen" + File.separator + "java"; outputFolder = "generated-code/JavaJaxRS-CXF"; - apiTestTemplateFiles.clear(); // TODO: add test template - + // clear model and api doc template as this codegen // does not support auto-generated markdown doc at the moment //TODO: add doc templates @@ -42,11 +41,10 @@ public JavaCXFServerCodegen() public void processOpts() { super.processOpts(); - + supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); - } @Override diff --git a/modules/swagger-codegen/src/main/resources/Java/model.mustache b/modules/swagger-codegen/src/main/resources/Java/model.mustache index f275a98f548..1d72c3a4efe 100644 --- a/modules/swagger-codegen/src/main/resources/Java/model.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/model.mustache @@ -5,8 +5,8 @@ package {{package}}; import java.util.Objects; {{#imports}} import {{import}}; -import javax.validation.constraints.*; {{/imports}} +import javax.validation.constraints.*; {{#serializableModel}}import java.io.Serializable;{{/serializableModel}} {{#models}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache new file mode 100644 index 00000000000..524f20dfb39 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache @@ -0,0 +1,59 @@ +{{>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 com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + + +{{^fullJavaUtil}} +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +{{/fullJavaUtil}} + +/** + * API tests for {{classname}} + */ +public class {{classname}}Test { + + private {{classname}} api; + + @Before + public void setup() { + JacksonJsonProvider provider = new JacksonJsonProvider(); + List providers = new ArrayList(); + providers.add(provider); + + api = JAXRSClientFactory.create("{{basePath}}", {{classname}}.class, providers); + } + + {{#operations}}{{#operation}} + /** + * {{summary}} + * + * {{notes}} + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void {{operationId}}Test() { + {{#allParams}} + {{{dataType}}} {{paramName}} = new {{{dataType}}}(); + {{/allParams}} + Response response = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + + {{#returnType}}{{{returnType}}} responseModel = response.readEntity({{{returnType}}}.class);{{/returnType}} + + // TODO: test validations + } + {{/operation}}{{/operations}} +} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/licenseInfo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/licenseInfo.mustache new file mode 100644 index 00000000000..861d97234cf --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/licenseInfo.mustache @@ -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. + */ diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache index 2c383a41a28..5a16499d15b 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/model.mustache @@ -2,6 +2,7 @@ package {{package}}; {{#imports}}import {{import}}; {{/imports}} +import javax.validation.constraints.*; {{#models}} {{#model}}{{#description}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index c214ae2ae84..26ff946af81 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -27,6 +27,15 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { * minimum: {{minimum}}{{/minimum}}{{#maximum}} * maximum: {{maximum}}{{/maximum}} **/ + {{#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}}{{#minimum}} + //@Min({{minimum}}){{/minimum}}{{#maximum}} + //@Max({{maximum}}){{/maximum}} {{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}} public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index 43d02dec937..c161b605836 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -108,12 +108,20 @@ ${junit-version} test + org.apache.cxf cxf-rt-rs-client 3.1.6 test + + + javax.validation + validation-api + 1.1.0.Final + provided + From 7b375d3ce32b1b1adee5e7dd9202c4d987d21a49 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sat, 2 Jul 2016 19:11:24 +0200 Subject: [PATCH 04/16] optimize mustache template structure, remove tabs #3280 #2549 --- .../src/main/resources/Java/pojo.mustache | 20 ++++++++++++------- .../src/main/resources/Java/pom.mustache | 10 +++++----- .../resources/JavaJaxRS/cxf/pojo.mustache | 20 ++++++++++++------- .../main/resources/JavaJaxRS/cxf/pom.mustache | 12 +++++------ 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/pojo.mustache b/modules/swagger-codegen/src/main/resources/Java/pojo.mustache index 0521e244074..a4f15f914f8 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pojo.mustache @@ -52,15 +52,21 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{#vendorExtensions.extraAnnotation}} {{vendorExtensions.extraAnnotation}} {{/vendorExtensions.extraAnnotation}} - {{#required}} +{{#required}} @NotNull{{/required}}{{! -}}{{#pattern}} - @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} - @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} +}} +{{#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}}{{#minimum}} - //@Min({{minimum}}){{/minimum}}{{#maximum}} - //@Max({{maximum}}){{/maximum}} + @Size(max={{maxLength}}){{/maxLength}}{{/minLength}} +{{#minimum}} + //@Min({{minimum}}) +{{/minimum}} +{{#maximum}} + //@Max({{maximum}}) +{{/maximum}} @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index 8c9006c8fc4..66e6aeb2517 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -178,11 +178,11 @@ - javax.validation - validation-api - 1.1.0.Final - provided - + javax.validation + validation-api + 1.1.0.Final + provided + diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index 26ff946af81..ad5ef14b9d6 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -27,15 +27,21 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { * minimum: {{minimum}}{{/minimum}}{{#maximum}} * maximum: {{maximum}}{{/maximum}} **/ - {{#required}} +{{#required}} @NotNull{{/required}}{{! -}}{{#pattern}} - @Pattern(regexp="{{pattern}}"){{/pattern}}{{#minLength}}{{#maxLength}} - @Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{#minLength}}{{^maxLength}} +}} +{{#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}}{{#minimum}} - //@Min({{minimum}}){{/minimum}}{{#maximum}} - //@Max({{maximum}}){{/maximum}} + @Size(max={{maxLength}}){{/maxLength}}{{/minLength}} +{{#minimum}} + //@Min({{minimum}}) +{{/minimum}} +{{#maximum}} + //@Max({{maximum}}) +{{/maximum}} {{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}} public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index c161b605836..f20c1f8bef6 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -115,13 +115,13 @@ 3.1.6 test - + - javax.validation - validation-api - 1.1.0.Final - provided - + javax.validation + validation-api + 1.1.0.Final + provided + From 956432ac31ba020e88c5497cf55250b1553e5a6c Mon Sep 17 00:00:00 2001 From: jfiala Date: Sat, 2 Jul 2016 19:21:05 +0200 Subject: [PATCH 05/16] refined dependency to swagger-jaxrs #2017 --- .../src/main/resources/JavaJaxRS/cxf/pom.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index f20c1f8bef6..f8a33fd7fe1 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -86,7 +86,7 @@ io.swagger - swagger-jersey2-jaxrs + swagger-jaxrs compile ${swagger-core-version} From f420da05924765004bd052944632d69993fc9f7a Mon Sep 17 00:00:00 2001 From: jfiala Date: Sat, 2 Jul 2016 19:51:44 +0200 Subject: [PATCH 06/16] refined annotations and line breaks #2549 --- .../src/main/resources/Java/pojo.mustache | 28 +++++++--- .../resources/JavaJaxRS/cxf/pojo.mustache | 51 +++++++++++++++---- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/pojo.mustache b/modules/swagger-codegen/src/main/resources/Java/pojo.mustache index a4f15f914f8..385fddfc036 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pojo.mustache @@ -49,18 +49,27 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali {{/maximum}} * @return {{name}} **/ - {{#vendorExtensions.extraAnnotation}} - {{vendorExtensions.extraAnnotation}} - {{/vendorExtensions.extraAnnotation}} {{#required}} - @NotNull{{/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}} +{{#minLength}} +{{#maxLength}} + @Size(min={{minLength}},max={{maxLength}}) +{{/maxLength}} +{{/minLength}} +{{#minLength}} +{{^maxLength}} + @Size(min={{minLength}}) +{{/maxLength}} +{{/minLength}} +{{^minLength}} +{{#maxLength}} + @Size(max={{maxLength}}) + {{/maxLength}} + {{/minLength}} {{#minimum}} //@Min({{minimum}}) {{/minimum}} @@ -68,6 +77,9 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali //@Max({{maximum}}) {{/maximum}} @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") +{{#vendorExtensions.extraAnnotation}} + {{vendorExtensions.extraAnnotation}} +{{/vendorExtensions.extraAnnotation}} public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index ad5ef14b9d6..357fe96dcc4 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -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; @@ -11,6 +12,9 @@ import javax.xml.bind.annotation.XmlEnum; }){{/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}} @@ -22,27 +26,52 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} {{#vars}} - /**{{#description}} - * {{{description}}}{{/description}}{{#minimum}} - * minimum: {{minimum}}{{/minimum}}{{#maximum}} - * maximum: {{maximum}}{{/maximum}} - **/ + /** + {{#description}} + * {{{description}}} + {{/description}} + {{^description}} + * Get {{name}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + * @return {{name}} + **/ {{#required}} - @NotNull{{/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}} +{{#minLength}} +{{#maxLength}} + @Size(min={{minLength}},max={{maxLength}}) +{{/maxLength}} +{{/minLength}} +{{#minLength}} +{{^maxLength}} + @Size(min={{minLength}}) +{{/maxLength}} +{{/minLength}} +{{^minLength}} +{{#maxLength}} + @Size(max={{maxLength}}) + {{/maxLength}} + {{/minLength}} {{#minimum}} //@Min({{minimum}}) {{/minimum}} {{#maximum}} //@Max({{maximum}}) {{/maximum}} - {{#vendorExtensions.extraAnnotation}}{{vendorExtensions.extraAnnotation}}{{/vendorExtensions.extraAnnotation}} + @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") +{{#vendorExtensions.extraAnnotation}} + {{vendorExtensions.extraAnnotation}} +{{/vendorExtensions.extraAnnotation}} public {{{datatypeWithEnum}}} {{getter}}() { return {{name}}; } From ee34013b4eda287d47d4fa2167e5dc74443fdb43 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 18:11:21 +0200 Subject: [PATCH 07/16] fix tabs instead of spaces... --- .../languages/JavaCXFServerCodegen.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java index b94f2d0c60d..8fa2ec71b8c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java @@ -12,9 +12,9 @@ import io.swagger.models.Operation; public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen -{ - public JavaCXFServerCodegen() - { +{ + public JavaCXFServerCodegen() + { super(); supportsInheritance = true; sourceFolder = "gen" + File.separator + "java"; @@ -34,24 +34,24 @@ public JavaCXFServerCodegen() embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf"; - } + } - @Override - public void processOpts() - { - super.processOpts(); - - supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen + @Override + public void processOpts() + { + super.processOpts(); + + 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"; - } + } + + @Override + public String getName() + { + return "jaxrs-cxf"; + } @Override public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map> operations) { From d47eaa9ca91d8684b33a79d6ab273bd46a694001 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 18:24:41 +0200 Subject: [PATCH 08/16] move annotations from getter to field for server model --- .../resources/JavaJaxRS/cxf/pojo.mustache | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index 357fe96dcc4..e916ea92c9c 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -23,24 +23,6 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{>enumClass}}{{/items}}{{/items.isEnum}} @XmlElement(name="{{baseName}}") - private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} - - {{#vars}} - /** - {{#description}} - * {{{description}}} - {{/description}} - {{^description}} - * Get {{name}} - {{/description}} - {{#minimum}} - * minimum: {{minimum}} - {{/minimum}} - {{#maximum}} - * maximum: {{maximum}} - {{/maximum}} - * @return {{name}} - **/ {{#required}} @NotNull {{/required}} @@ -67,8 +49,26 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{/minimum}} {{#maximum}} //@Max({{maximum}}) -{{/maximum}} +{{/maximum}} @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /** + {{#description}} + * {{{description}}} + {{/description}} + {{^description}} + * Get {{name}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + * @return {{name}} + **/ {{#vendorExtensions.extraAnnotation}} {{vendorExtensions.extraAnnotation}} {{/vendorExtensions.extraAnnotation}} From 8c8f587192939d59dc37f3e4e1ef9a56efc1a75d Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 18:24:41 +0200 Subject: [PATCH 09/16] cleanup tabs --- .../resources/JavaJaxRS/cxf/pojo.mustache | 40 +++++++++---------- .../main/resources/JavaJaxRS/cxf/pom.mustache | 10 ++--- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index 357fe96dcc4..af565cdbf35 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -8,7 +8,7 @@ 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}} @@ -23,24 +23,6 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{>enumClass}}{{/items}}{{/items.isEnum}} @XmlElement(name="{{baseName}}") - private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} - - {{#vars}} - /** - {{#description}} - * {{{description}}} - {{/description}} - {{^description}} - * Get {{name}} - {{/description}} - {{#minimum}} - * minimum: {{minimum}} - {{/minimum}} - {{#maximum}} - * maximum: {{maximum}} - {{/maximum}} - * @return {{name}} - **/ {{#required}} @NotNull {{/required}} @@ -67,8 +49,26 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{/minimum}} {{#maximum}} //@Max({{maximum}}) -{{/maximum}} +{{/maximum}} @ApiModelProperty({{#example}}example = "{{example}}", {{/example}}{{#required}}required = {{required}}, {{/required}}value = "{{{description}}}") + private {{{datatypeWithEnum}}} {{name}} = {{{defaultValue}}};{{/vars}} + + {{#vars}} + /** + {{#description}} + * {{{description}}} + {{/description}} + {{^description}} + * Get {{name}} + {{/description}} + {{#minimum}} + * minimum: {{minimum}} + {{/minimum}} + {{#maximum}} + * maximum: {{maximum}} + {{/maximum}} + * @return {{name}} + **/ {{#vendorExtensions.extraAnnotation}} {{vendorExtensions.extraAnnotation}} {{/vendorExtensions.extraAnnotation}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index f8a33fd7fe1..9019f5e7332 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -110,11 +110,11 @@ - org.apache.cxf - cxf-rt-rs-client - 3.1.6 - test - + org.apache.cxf + cxf-rt-rs-client + 3.1.6 + test + javax.validation From e44bb1e372e41f4bce94d7345db684a4dff2ffe6 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 18:40:45 +0200 Subject: [PATCH 10/16] add example for gzipping #2017 --- .../resources/JavaJaxRS/cxf/api_test.mustache | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache index 524f20dfb39..a7f92f667ea 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache @@ -9,9 +9,12 @@ 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; +import org.apache.cxf.transport.common.gzip.GZIPInInterceptor; +import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; - {{^fullJavaUtil}} import java.util.ArrayList; import java.util.HashMap; @@ -28,11 +31,24 @@ public class {{classname}}Test { @Before public void setup() { - JacksonJsonProvider provider = new JacksonJsonProvider(); - List providers = new ArrayList(); - providers.add(provider); - - api = JAXRSClientFactory.create("{{basePath}}", {{classname}}.class, providers); + JacksonJsonProvider provider = new JacksonJsonProvider(); + List providers = new ArrayList(); + providers.add(provider); + + api = JAXRSClientFactory.create("{{basePath}}", {{classname}}.class, providers); + + org.apache.cxf.jaxrs.client.Client client = WebClient.client(api); + + ClientConfiguration config = WebClient.getConfig(client); + + // 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()); + } {{#operations}}{{#operation}} @@ -51,7 +67,7 @@ public class {{classname}}Test { {{/allParams}} Response response = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - {{#returnType}}{{{returnType}}} responseModel = response.readEntity({{{returnType}}}.class);{{/returnType}} + {{#returnType}}{{{returnType}}} responseModel = response.readEntity({{{returnType}}}.class);{{/returnType}} // TODO: test validations } From 6b1b883e21468794fdb5229f40f2bbc04605d624 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 20:53:54 +0200 Subject: [PATCH 11/16] add complete WAR to cxf-server #2017 --- .../languages/JavaCXFServerCodegen.java | 22 ++++++ .../main/resources/JavaJaxRS/cxf/api.mustache | 9 ++- .../JavaJaxRS/cxf/apiServiceImpl.mustache | 44 ++++++++++++ .../resources/JavaJaxRS/cxf/api_test.mustache | 4 +- .../JavaJaxRS/cxf/context.xml.mustache | 71 +++++++++++++++++++ .../JavaJaxRS/cxf/jboss-web.xml.mustache | 7 ++ .../main/resources/JavaJaxRS/cxf/pom.mustache | 61 +++++++++++++--- .../main/resources/JavaJaxRS/cxf/web.mustache | 23 ++++++ 8 files changed, 229 insertions(+), 12 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/apiServiceImpl.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/context.xml.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/jboss-web.xml.mustache create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/web.mustache diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java index 8fa2ec71b8c..a2c843514e7 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java @@ -11,15 +11,30 @@ import io.swagger.codegen.SupportingFile; import io.swagger.models.Operation; +/** + * TODO #2017: + * - reuse bean-validation-annotations in Java? + * - pom.xml: maybe add cxf-version property + * - api_test.mustache: add switch for using gzip in test cases? + * + * + * + */ public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen { public JavaCXFServerCodegen() { super(); + supportsInheritance = true; + + artifactId = "swagger-cxf-server"; + sourceFolder = "gen" + File.separator + "java"; outputFolder = "generated-code/JavaJaxRS-CXF"; + 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 @@ -45,6 +60,13 @@ public void processOpts() supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + writeOptional(outputFolder, new SupportingFile("web.mustache", + ("src/main/webapp/WEB-INF"), "web.xml")); + writeOptional(outputFolder, new SupportingFile("context.xml.mustache", + ("src/main/webapp/WEB-INF"), "context.xml")); + writeOptional(outputFolder, new SupportingFile("jboss-web.xml.mustache", + ("src/main/webapp/WEB-INF"), "jboss-web.xml")); + } @Override diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache index 7d57616610d..c949f117f8d 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache @@ -12,7 +12,11 @@ import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.ext.multipart.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + @Path("/") +@Api(value = "/", description = "{{description}}") public interface {{classname}} { {{#operations}} {{#operation}} @@ -20,7 +24,10 @@ public interface {{classname}} { {{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}} {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} - public Response {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}); +{{#summary}} +@ApiOperation(value = "{{summary}}") +{{/summary}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}); {{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/apiServiceImpl.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/apiServiceImpl.mustache new file mode 100644 index 00000000000..dde547f91c6 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/apiServiceImpl.mustache @@ -0,0 +1,44 @@ +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; + +@Path("/") +{{#description}} +@Api(value = "/", description = "{{description}}") +{{/description}} +public class {{classname}}ServiceImpl implements {{classname}} { +{{#operations}} +{{#operation}} + @{{httpMethod}} + {{#subresourceOperation}}@Path("{{path}}"){{/subresourceOperation}} + {{#hasConsumes}}@Consumes({ {{#consumes}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} }){{/hasConsumes}} + {{#hasProduces}}@Produces({ {{#produces}}"{{{mediaType}}}"{{#hasMore}}, {{/hasMore}}{{/produces}} }){{/hasProduces}} + {{! add description for CXF WADL (must be added to implementation class }} +{{#summary}} + @Description(value = "{{summary}}", target = DocTarget.METHOD) +{{/summary}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) { + // TODO: Implement... + + {{#returnType}}return null;{{/returnType}} + } + +{{/operation}} +} +{{/operations}} + diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache index a7f92f667ea..7d275deb8c2 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api_test.mustache @@ -65,9 +65,7 @@ public class {{classname}}Test { {{#allParams}} {{{dataType}}} {{paramName}} = new {{{dataType}}}(); {{/allParams}} - Response response = api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); - - {{#returnType}}{{{returnType}}} responseModel = response.readEntity({{{returnType}}}.class);{{/returnType}} + {{#returnType}}{{{returnType}}} response = {{/returnType}}api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); // TODO: test validations } diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/context.xml.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/context.xml.mustache new file mode 100644 index 00000000000..1c7aeb4d64d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/context.xml.mustache @@ -0,0 +1,71 @@ + + + + + + + + + + + + +{{#apiInfo}} +{{#apis}} + +{{/apis}} +{{/apiInfo}} + + + + + + + + + + + + + + + + + + + + +{{#apiInfo}} +{{#apis}} + +{{/apis}} +{{/apiInfo}} + + + + + + + + + + + + diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/jboss-web.xml.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/jboss-web.xml.mustache new file mode 100644 index 00000000000..ef688c10e91 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/jboss-web.xml.mustache @@ -0,0 +1,7 @@ + + + + + swagger-cxf-server + + diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index 9019f5e7332..5144bd95c9f 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -2,7 +2,7 @@ 4.0.0 {{groupId}} {{artifactId}} - jar + war {{artifactId}} {{artifactVersion}} @@ -25,7 +25,7 @@ - + org.codehaus.mojo build-helper-maven-plugin @@ -81,6 +81,14 @@ + + + + maven-war-plugin + + true + + @@ -108,6 +116,13 @@ ${junit-version} test + + + javax.validation + validation-api + 1.1.0.Final + provided + org.apache.cxf @@ -115,13 +130,43 @@ 3.1.6 test - + + - javax.validation - validation-api - 1.1.0.Final - provided + org.apache.cxf + cxf-rt-frontend-jaxrs + 3.1.6 + compile + + org.apache.cxf + cxf-rt-rs-service-description + 3.1.6 + compile + + + org.apache.cxf + cxf-rt-ws-policy + 3.1.6 + compile + + + org.apache.cxf + cxf-rt-wsdl + 3.1.6 + compile + + + + org.springframework + spring-context + 4.2.5.RELEASE + + + org.springframework + spring-web + 4.2.5.RELEASE + diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/web.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/web.mustache new file mode 100644 index 00000000000..9d905ae076b --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/web.mustache @@ -0,0 +1,23 @@ + + + + + contextConfigLocation + WEB-INF/context.xml + + + org.springframework.web.context.ContextLoaderListener + + + CXF Service Servlet + CXFServiceServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServiceServlet + /rest/* + + + From bfc597c83db4a0d4a5f29b33b307935946970331 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 21:11:04 +0200 Subject: [PATCH 12/16] add readme + rework pom #2017 --- .../languages/JavaCXFServerCodegen.java | 3 +++ .../main/resources/JavaJaxRS/cxf/pom.mustache | 21 +++++++++-------- .../main/resources/JavaJaxRS/cxf/readme.md | 23 +++++++++++++++++++ 3 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/readme.md diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java index a2c843514e7..5ccb88459e3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaCXFServerCodegen.java @@ -58,8 +58,11 @@ public void processOpts() super.processOpts(); supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen + writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml")); + writeOptional(outputFolder, new SupportingFile("readme.md", "", "readme.md")); + writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml")); writeOptional(outputFolder, new SupportingFile("context.xml.mustache", diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache index 5144bd95c9f..40a6135e636 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pom.mustache @@ -120,14 +120,14 @@ javax.validation validation-api - 1.1.0.Final + ${beanvalidation-version} provided org.apache.cxf cxf-rt-rs-client - 3.1.6 + ${cxf-version} test @@ -135,37 +135,37 @@ org.apache.cxf cxf-rt-frontend-jaxrs - 3.1.6 + ${cxf-version} compile org.apache.cxf cxf-rt-rs-service-description - 3.1.6 + ${cxf-version} compile org.apache.cxf cxf-rt-ws-policy - 3.1.6 + ${cxf-version} compile org.apache.cxf cxf-rt-wsdl - 3.1.6 + ${cxf-version} compile - + org.springframework spring-context - 4.2.5.RELEASE + ${spring-version} org.springframework spring-web - 4.2.5.RELEASE + ${spring-version} @@ -187,6 +187,9 @@ 4.12 1.1.7 2.5 + 1.1.0.Final + 4.2.5.RELEASE + 3.1.6 UTF-8 diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/readme.md b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/readme.md new file mode 100644 index 00000000000..27925cedf44 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/readme.md @@ -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 + + From 84efac353023010d77e5d140d568ad2eab68bd35 Mon Sep 17 00:00:00 2001 From: jfiala Date: Sun, 3 Jul 2016 21:11:55 +0200 Subject: [PATCH 13/16] add todo for switch #2549 --- .../io/swagger/codegen/languages/JavaClientCodegen.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 27e95190648..85cd8e519ef 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -9,6 +9,13 @@ import java.io.File; import java.util.*; +/** + * TODO #2549: + * - add switch for bean-validation-annotations? + * + * + * + */ public class JavaClientCodegen extends AbstractJavaCodegen { @SuppressWarnings("hiding") private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class); @@ -164,7 +171,7 @@ public Map postProcessOperations(Map objs) { operation.returnType = "Void"; } if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/")) - operation.path = operation.path.substring(1); + operation.path = operation.path.substring(1); } } } From 11907bed548b4e0cfccbbab0743a4a510d4f7a8e Mon Sep 17 00:00:00 2001 From: jfiala Date: Mon, 4 Jul 2016 20:58:00 +0200 Subject: [PATCH 14/16] fix for sourceJavaFolder #2437 --- .../swagger/codegen/plugin/CodeGenMojo.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java index 261d539e2e5..d786ad5b192 100644 --- a/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java +++ b/modules/swagger-codegen-maven-plugin/src/main/java/io/swagger/codegen/plugin/CodeGenMojo.java @@ -1,5 +1,23 @@ package io.swagger.codegen.plugin; +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvp; +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyImportMappingsKvp; +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyInstantiationTypesKvp; +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyLanguageSpecificPrimitivesCsv; +import static io.swagger.codegen.config.CodegenConfiguratorUtils.applyTypeMappingsKvp; +import static org.apache.commons.lang3.StringUtils.isNotEmpty; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + /* * Copyright 2001-2005 The Apache Software Foundation. * @@ -19,25 +37,9 @@ import io.swagger.codegen.CliOption; import io.swagger.codegen.ClientOptInput; import io.swagger.codegen.CodegenConfig; +import io.swagger.codegen.CodegenConstants; import io.swagger.codegen.DefaultGenerator; import io.swagger.codegen.config.CodegenConfigurator; -import io.swagger.models.Swagger; -import io.swagger.parser.SwaggerParser; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import static io.swagger.codegen.config.CodegenConfiguratorUtils.*; -import static org.apache.commons.lang3.StringUtils.isNotEmpty; /** * Goal which generates client/server code from a swagger json/yaml definition. @@ -288,7 +290,8 @@ public void execute() throws MojoExecutionException { } if (addCompileSourceRoot) { - project.addCompileSourceRoot(output.toString()); + String sourceJavaFolder = output.toString() + "/" + configOptions.get(CodegenConstants.SOURCE_FOLDER); + project.addCompileSourceRoot(sourceJavaFolder); } } } From d41726be627d51a6e49183fa10af8d2c2e59a647 Mon Sep 17 00:00:00 2001 From: jfiala Date: Mon, 4 Jul 2016 21:16:27 +0200 Subject: [PATCH 15/16] document implementation of Java Bean-Validation-API support #2549 --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index a549adec5b5..42026ded2f8 100644 --- a/README.md +++ b/README.md @@ -582,6 +582,32 @@ and specify the `classname` when running the generator: Your subclass will now be loaded and overrides the `PREFIX` value in the superclass. +### Java Bean Validation support + +Java Bean Validation annotations are supported: + +Annotation | Swagger-API | Description +@DecimalMax (max for BigDecimal) | maxLength | not yet supported, see #2549 +@DecimalMin (min for BigDecimal) | minLength | not yet supported, see #2549 +@Max | maximum | The value of the field or property must be an integer value lower than or equal to the number in the value element. +@Min | minimum | The value of the field or property must be an integer value greater than or equal to the number in the value element. +@NotNull | required=true | The value of the field or property must not be null. +@Pattern | pattern | The value of the field or property must match the regular expression defined in the regexp element. +@Size | minLength/maxLength | The size of the field or property is evaluated and must match the specified boundaries. + +See http://docs.oracle.com/javaee/6/tutorial/doc/gircz.html for the full list of annotations. + +The following annotations currently don't have an equivalent in the Swagger-API spec: +* @AssertFalse +* @AssertTrue +* @Digits +* @Future +* @Null +* @Past + +Languages with Bean Validation support: Java, JAX-RS CXF + + ### Bringing your own models Sometimes you don't want a model generated. In this case, you can simply specify an import mapping to tell From c593f962b8ee559b34f3a26a679e96e86a3632ac Mon Sep 17 00:00:00 2001 From: jfiala Date: Mon, 4 Jul 2016 21:39:32 +0200 Subject: [PATCH 16/16] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 42026ded2f8..e619b5948fb 100644 --- a/README.md +++ b/README.md @@ -587,6 +587,7 @@ Your subclass will now be loaded and overrides the `PREFIX` value in the supercl Java Bean Validation annotations are supported: Annotation | Swagger-API | Description +---------- | ----------- | ----------- @DecimalMax (max for BigDecimal) | maxLength | not yet supported, see #2549 @DecimalMin (min for BigDecimal) | minLength | not yet supported, see #2549 @Max | maximum | The value of the field or property must be an integer value lower than or equal to the number in the value element.