swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.94k stars 6.03k forks source link

[Jaxrs-Resteasy] Improvements for Jaxrs-Resteasy #4512

Open jfiala opened 7 years ago

jfiala commented 7 years ago
Description

The generated code stubs are way to complicated, in fact only the following files are needed for Resteasy (verified with Jboss EAP 7):

Additional Fixes

The current state of #4712 allows to generate a simple structure with interfaces holding all JaxRS-annotations and a simple implementation class. Registration for JaxRS is done by extending Jaxrs Application. It has been verified to work for Jboss EAP 6 + 7 as no resteasy-specific libraries are included ( resteasy-jackson2-provider is now provided as opposed to jaxrs-resteasy).

Datetime-Support

This language supports Java8 and Joda datetime using the JacksonConfig, the needed dependencies included automatically (see pom.mustache).

I added the flag "joda" to AbstractJavaCodegen.java to allow checking for joda in the mustache templates.

Further Enhancements
Questions
Swagger-codegen version

2.2.2-SNAPSHOT

Related issues

4447 regarding the Swagger annotations

4461 regarding WAR-file

4123 for enums

3446 for tag support

Suggest a Fix

If you like, I can provide a new simplified Resteasy language. Using the dynamic Swagger contract generator it provides true turnaround development...

mbucc commented 7 years ago

@jfiala What do you think about putting the EAP version in the language name? For example, renaming jaxrs-resteasy to jaxrs-reasteasy-eap7? RestEasy 3 (and other libs in pom) are not included in EAP6, so jaxrs-resteasy did not build for me out of the box.

jfiala commented 7 years ago

@mbucc I think this would be a good starting point, as I worked only with EAP 7 here, this way we can also target for 2.2.2. Later if we can warrant backwards compatibility somehow for EAP 6 we can then replace jaxrs-resteasy (for 2.3).

I'd add a new language jaxrs-resteasy-eap7 and wouldn't change the existing jaxrs-resteasy in the first place.

@wing328 what do you think?

mbucc commented 7 years ago

@jfiala FWIW, you can rename existing jaxrs-resteasy if you like. It will not work with eap6.

jfiala commented 7 years ago

@mbucc for which Resteasy/Jboss version was the current implementation supposed for? I'd like to greatly simplify the generated files as there are only interfaces/models and one initialization class needed to work with Jboss EAP 7.

mbucc commented 7 years ago

@jfiala here is my understanding: existing jaxrs-resteasy codegen only works for EAP 7.

Note that the servlet api version could be upgraded as well; 2.5 was last used in EAP 5: (https://access.redhat.com/articles/113373)

I can contribute files for eap 6, assuming I can get past the ApiResponse issue I opened in #4617.

mbucc commented 7 years ago

@jfiala I just realized something. Resteasy is a stand alone library, so I suspect the author built this codegen for that scenario.

At work, I use JBoss container, which provides RestEasy, so I was only thinking about this codegen in context of JBoss. But there are other containers where the war artifact built here will work just fine.

Sorry for the diversion!

(Seems like I should simply create a jboss6-resteasy codegen based on this one. Sound reasonable to you?)

jfiala commented 7 years ago

@mbucc OK, thx for the clarification. I'd like to provide the first draft with name resteasy-jboss and I'll test it for both jboss 6 and 7 eap (better put language first, then target jee server). In the next step/release 2.3, we could replace the existing resteasy language. It would be great if you can give it a test run, we can then also check how to fix your issue #4617.

jfiala commented 7 years ago

@mbucc I added a first re-implementation of Jaxrs Resteasy in PR #4712, please take a look when you have time.

I added all resteasy dependencies (also resteasy-jackson2-provider) as provided, so it doesn't depend on a specific resteasy version. I verified it to deploy on Jboss EAP 6 + 7 without errors.

jfiala commented 7 years ago

I also added the option to generate the Swagger contract dynamically.

jfiala commented 7 years ago

@mbucc @wing328 Jaxrs Resteasy for EAP 6 + 7 is now fully implemented and tested with Joda + Java8 datetime support. Pls take a look when you have time, see PR #4517 .

wing328 commented 7 years ago

@mbucc may I know if you've time to run some tests for this change? Here are the steps:

git checkout -b jfiala-jaxrs_resteasy-eap_4512 master
git pull https://github.com/jfiala/swagger-codegen.git jaxrs_resteasy-eap_4512
mbucc commented 7 years ago

@wing328 @jfiala Would be happy to. Give me a week or two.

BTW, is there a docker container for JBoss 7 you like to test with?