Open mohsen1 opened 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.
@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?
@jfiala thanks for the suggestion. What about leveraging .swagger-codegen-ignore
file to indicate those implementation classes should not be generated?
@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.
@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.
@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
@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).
From https://github.com/swagger-api/swagger-editor/issues/423