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
17.03k stars 6.03k forks source link

JAX-RS should have Apache CXF Interface gateway #714

Open mohsen1 opened 9 years ago

mohsen1 commented 9 years ago

From https://github.com/swagger-api/swagger-editor/issues/423

Generate Server - JAX-RS should have Apache CXF Interface gateway, while it should not have Implementation class by itself. This gives developers seamless ability to be able to generate Apache CXF based JAX-RS Service (rather than presently produced Jersey API based Implementation). Assume the application is to go through Agile cycle, and is supposed to have a contract change in future, providing interface in server code to be extended in a different place to write complete service implementation would keep the Server Interface API and Implementation independent.

olensmar commented 9 years ago

I agree we should have something like this - it has come up in several discussions at Swagger meetups recently and would make an iterative spec-first workflow easier to implement.

jfiala commented 8 years ago

@wing328 currently the implementation classes are always generated at the servers supporting it (currently 4 - JavaResteasyServerCodegen, JavaJerseyServerCodegen, JavaJAXRSCXFCDIServerCodegen, JavaCXFServerCodegen). I think the easiest solution would be to add a CLI switch to indicate if the impl. classes should be generated and implement it for the 4 languages?

wing328 commented 8 years ago

@jfiala thanks for the suggestion. What about leveraging .swagger-codegen-ignore file to indicate those implementation classes should not be generated?

jfiala commented 8 years ago

@wing328 Thx for the input, this works perfectly.

However, I think maybe a separate option would be better because using the ignore-file users have to post-process the generated output, which is undesirable e.g. for output generated during a maven build which is usually intented to run only against generated folders. So I think the decision to omit implementation classes should be done before generating the files. So I'd slightly favor a separate option like GENERATE_IMPL_CLASS.

jfiala commented 8 years ago

@wing328 a purely contract first approach in the maven build currently faces the following challenges: By default, generated classes go to target/generated-sources - there the .swagger-codegen-ignore file cannot be used.

It should be possible to only generate the interfaces/models, this would probably make sense being the default for the swagger-codegen-maven-plugin (people expect this behavior when coming from wadl2java generators).

In any way, I think there should be CLI options for switching pom.xml, impl classes, test classes on/off so users can decide what they want to generate easily.

wing328 commented 7 years ago

@jfiala I just did a test with ./bin/jaxrs-cxf-petstore-server.sh and the files didn't go to the folder target/generated-sources.

Here is part of the output:

[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/williamcheng/Code/swagger-api/swagger-codegen/samples/server/petstore/jaxrs-cxf/src/gen/java/io/swagger/api/UserApi.java
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /Users/williamcheng/Code/swagger-api/swagger-codegen/samples/server/petstore/jaxrs-cxf/src/main/java/io/swagger/api/impl/UserApiServiceImpl.java
[main] INFO io.swagger.codegen.DefaultGenerator - File exists. Skipped overwriting /Users/williamcheng/Code/swagger-api/swagger-codegen/samples/server/petstore/jaxrs-cxf/src/test/java/io/swagger/api/UserApiTest.java
jfiala commented 7 years ago

@wing328 I was talking about the swagger-codegen-maven-plugin, there the default is target/generated-sources/swagger/ if no output folder is specified. Currently there is no way in the target-folder to reduce the generated output to interfaces/models only (as it always will get rewritten).