Skip to content

Conversation

@jfiala
Copy link
Contributor

@jfiala jfiala commented Oct 14, 2016

Overview

  • added interfaces to model language feature support (io.swagger.codegen.languages.features)
  • add beanvalidation annotation support
  • add new language for CXF client (jaxrs-cxf, server moved to jaxrs-cxf-server)

Language Java

Language jaxrs-cxf-server (renamed from jaxrs-cxf)

  • add beanvalidation annotation support to language jaxrs-cxf Jaxrs-CXF missing mustache variables for javax.validation framework #2615 (using centralized beanValidation.mustache file)
  • add spring server generator to jaxrs-cxf (see also Generating Java Rest Client based on CXF  #2017 )
  • spring server: support CXF features using CLI-switches:
    • SwaggerFeature
    • WadlGenerator
    • Multipart
    • Gzip
    • Logging
    • automatic BeanValidation (JEE 7+ - BeanValidation 1.1)
  • support CXF features for Unittests using CLI switches:
    • Gzip
    • Logging
    • automatic BeanValidation (BeanValidation 1.1)
  • support Spring Boot embedded server
  • support Spring Boot integration tests

Language jaxrs-cxf (new)

for more details also see former PR #3281

ideas for further issues

CXF minor improvements

  • improve CXF QueryParam BeanValidation formatting (currently reused from beanValidation.mustache, but will add a newline after each beanvalidation annotation).
  • add separate flags for controlling junit test gzip/logging/... support (is currently generated automatically for server + junit-tests if switched on)* add option to generate Jboss files (jboss-web.xml etc.)
  • add a JbossFeature and flag to only generate jboss-specific files if requested
  • add flag for switching JAXB annotations on/off
  • check for void in apiServiceImpl to suppress the return statement (instead of returnType, which is void for no returnType...)

extracted to issue #4088

Other languages

Further CXF improvements

  • maybe add further CXF configuration scenarios (blueprint)

wing328 and others added 30 commits July 2, 2016 17:36
@wing328
Copy link
Contributor

wing328 commented Oct 22, 2016

@jfiala yup, will continue the review this weekend and merge if no further question from me.

@jfiala
Copy link
Contributor Author

jfiala commented Oct 23, 2016

@wing328 I just did some integration tests using swagger-codegen-maven-plugin, version 2.2.1.
If I run using the maven-plugin, it is unable to find the subtemplate referenced at JavaJaxRS/cxf/queryParams.mustache:
{{>../../java/beanValidation}}
java.lang.RuntimeException: can't load template JavaJaxRS\cxf....\java\beanValidation.mustache

However, at JavaJaxRS/cxf/pojo.mustache the same reference works without troubles.
And both references are working if I use the CLI instead of the maven plugin.
Also setting the templateDirectory at the configuration of the maven plugin doesn't change the behaviour.

Subtemplating across directories in mustache-files hasn't been used in the project so far, so this hasn't popped up yet.

Pls let me know if I should use a copy of beanValidation.mustache for cxf for now until this is analyzed/fixed ...? Should I create a separate issue for this?

@wing328
Copy link
Contributor

wing328 commented Oct 23, 2016

Pls let me know if I should use a copy of beanValidation.mustache for cxf for now until this is analyzed/fixed ...? Should I create a separate issue for this?

Please avoid using relative path and use a copy of the mustache file instead.

@jfiala
Copy link
Contributor Author

jfiala commented Oct 23, 2016

@wing328 changed to local copy + successfully verified with maven.

@wing328
Copy link
Contributor

wing328 commented Oct 24, 2016

@jfiala I generated the jaxrs-cxf-client using your branch and got the following error when running mvn test:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project swagger-jaxrs-client: Compilation failure: Compilation failure:
[ERROR] /private/var/tmp/jaxrs-cxf-client/tmp5/src/test/java/io/swagger/api/StoreApiTest.java:[110,24] no suitable constructor found for Long()
[ERROR] constructor java.lang.Long.Long(java.lang.String) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] constructor java.lang.Long.Long(long) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] /private/var/tmp/jaxrs-cxf-client/tmp5/src/test/java/io/swagger/api/PetApiTest.java:[97,22] no suitable constructor found for Long()
[ERROR] constructor java.lang.Long.Long(java.lang.String) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] constructor java.lang.Long.Long(long) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] /private/var/tmp/jaxrs-cxf-client/tmp5/src/test/java/io/swagger/api/PetApiTest.java:[114,31] java.util.List is abstract; cannot be instantiated
[ERROR] /private/var/tmp/jaxrs-cxf-client/tmp5/src/test/java/io/swagger/api/PetApiTest.java:[130,29] java.util.List is abstract; cannot be instantiated
[ERROR] /private/var/tmp/jaxrs-cxf-client/tmp5/src/test/java/io/swagger/api/PetApiTest.java:[146,22] no suitable constructor found for Long()
[ERROR] constructor java.lang.Long.Long(java.lang.String) is not applicable
[ERROR] (actual and formal argument lists differ in length)
[ERROR] constructor java.lang.Long.Long(long) is not applicable
[ERROR] (actual and formal argument lists differ in length)

Here is the command I used:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l jaxrs-cxf-client \
-o /var/tmp/jaxrs-cxf-client/tmp5/ 

Did you get similar error when using the jaxrs-cxf-client client?

@jfiala
Copy link
Contributor Author

jfiala commented Oct 24, 2016

@wing328 I did a clean install across the whole swagger-codegen project and it ran successfully without errors, probably because the generated projects themselvers are not verified with mvn clean install automatically...

I verified the errors you had now directly using:
io.swagger.codegen.Codegen -i C:\projects\swagger-codegen_jfiala\modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l jaxrs-cxf-client -o c:\temp\swagger-codegen-x_cxf_client -c c:\temp\swagger_config.json

swagger_config.json has all CLI flags turned on:

{
"useBeanValidation": "true",
"useGzipFeature": "true",
"useLoggingFeature": "true"
"generateApiTests": "true"
}

And then run mvn clean install on the generated project:
At the test client, currently placeholders are generated for all the parameters with new and the method invocation is not commented out. This is causing the errors during the compilation.
(it was intented to add more comfort for the developer - so they don't have to type the invocations themselves).

I can replace them with "null" and comment out the invocation itself so the generated test cases can be compiled (like this is the case for the Java test cases)?
Alternatively, I can comment out the parameter preparation as well?

Additionally, the jaxrs-cxf (server) now reuses the mustache template of jaxrs-cxf-client (by using the same template path). I think this makes sense, because they are identical, but if you prefer to have strictly separation of languages, I'd have to copy all templates into the mustache template directory JavaJaxRS/cxf/server (and JavaJaxRS/cxf would be the path of the client, or then even better JavaJaxRS/cxf/client to make things clear)?

@wing328
Copy link
Contributor

wing328 commented Oct 24, 2016

I can replace them with "null" and comment out the invocation itself so the generated test cases can be compiled (like this is the case for the Java test cases)?

Yes, please.

@wing328
Copy link
Contributor

wing328 commented Oct 24, 2016

FYI. For jaxrs-cxf, I got the following errors related to implementation class:

[INFO] -------------------------------------------------------------
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/PetApiServiceImpl.java:[25,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/PetApiServiceImpl.java:[31,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/PetApiServiceImpl.java:[55,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/PetApiServiceImpl.java:[61,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java:[24,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java:[30,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java:[36,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java:[42,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java:[60,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java:[66,16] cannot return a value from method whose result type is void
[ERROR] /private/var/tmp/jaxrs-cxf/tmp5/src/main/java/io/swagger/api/impl/StoreApiServiceImpl.java:[24,16] cannot return a value from method whose result type is void
[INFO] 11 errors 

I believe these errors already present in the latest master so I'll create another issue to track it.

@jfiala
Copy link
Contributor Author

jfiala commented Oct 24, 2016

@wing328: fixed the tests, now you can generate with the petstore without results after mvn install.

Regarding Impl.: The "return null;" will be generated only if the returnType is set, I didn't get any errors here! The problem is that "void" is set as returnType, so we need a flag to indicate that the returnType is void, then we can check for this in the mustache templates.

The other server stub generators get around this by using a generic JAXRS-Response, but IMHO it is much better to deal with the "real" objects instead of the generic JAXRS-Response, the Response is then wrapped automatically by CXF.

@jfiala
Copy link
Contributor Author

jfiala commented Oct 24, 2016

@wing328 the current master jaxrs-server doesn't include the apiServiceImpl.mustache, this was not supported there (https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf)

To assemble the implementation class correctly (without compile-errors) I need a flag to check if the returnType is void or not to generate correctly.

This should also be fixed in all Java api_test.mustache files, as they all would generate:

// void response = ...

because they all check for returnType and not for void:

// {{#returnType}}{{{returnType}}} response = 

which only compiles because its commented out :).

@wing328
Copy link
Contributor

wing328 commented Oct 24, 2016

To assemble the implementation class correctly (without compile-errors) I need a flag to check if the returnType is void or not to generate correctly.

I'll look into that after this PR is merged into master and add the flag if needed.

@jfiala
Copy link
Contributor Author

jfiala commented Oct 24, 2016

great, thank you!

@wing328
Copy link
Contributor

wing328 commented Oct 24, 2016

   /**
   * Get integer
   * minimum: 10.0
   * maximum: 100.0
   * @return integer
  **/
  //@Min(10.0)
  //@Max(100.0)
  @ApiModelProperty(example = "null", value = "")
  public Integer getInteger() {
    return integer;
  }

I noticed that @Min and @Max are commented out, probably due to decimal value used instead of integer.

If we can fix the min and max value with respect to the type, we should be able to generate uncommented constraints, right?

@jfiala
Copy link
Contributor Author

jfiala commented Oct 24, 2016

@wing328 Yes exactly, this has been discussed here #2615, if Codegen will output integer values here, we can remove the comments in the template (or use a different mustache variable).

@wing328
Copy link
Contributor

wing328 commented Oct 25, 2016

@jfiala I've created the branch jfiala-jaxrs_cxf_2017b with resolved conflicts and will squash and merge the commits (owned by you) into master after all CI tests pass.

wing328 added a commit that referenced this pull request Oct 25, 2016
* 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 82df5e6, reversing
changes made to 65e87f2.

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 c752ba8.

* Revert "re-create bin folder"

This reverts commit 8a6d413.

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 8a6d413.

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 d4b5c9a.

* Revert "Revert "re-create bin folder""

This reverts commit 4369b35.

* Revert "re-create bin folder"

This reverts commit 8a6d413.

* Revert "temporary solution for pattern - move to AbstractJavaCodegen #2549"

This reverts commit 82df5e6, reversing
changes made to 65e87f2.

* 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
@wing328
Copy link
Contributor

wing328 commented Oct 25, 2016

@jfiala merged via #4068

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants