I used the swagger codegen to generate jaxrs server side classes and also client side java classes.
This is the command I used to generate the classes
java -jar modules/swagger-codegen-distribution/target/swagger-codegen-distribution-2.1.2-M1.jar -i /Users/me/Workspace/swagger-codegen/samples/yaml/echo.yaml -l jaxrs -o samples/server/echo/java
The server code that was generated had a place holder to write my "magic".
public Response echo(@ApiParam(value = "" )@HeaderParam("headerParam") String headerParam,
@ApiParam(value = "",required=true) @QueryParam("message") String message)
throws NotFoundException {
// do some magic!
return Response.ok().entity(new ApiResponseMessage(ApiResponseMessage.OK, "magic!")).build();
}
I added the "magic" in the "echo" method and regenerated the code, only to see it wiped out. One way to avoid losing custom code is to modify the codegen template to generate interface instead of a class. Then I can have all the custom code in the implemented class.
I am trying to find out if there is a way I can preserve the custom "magic" even after regenerating the code or if there is a better way of handling this situation than changing the template to generate interfaces instead of classes.
The latest master of Swagger Codegen allows you to specify files not to be overwritten in .swagger-codegen-ignore (similar to .gitignore) during code generation.
Please pull the latest master of Swagger Codegen to give it a try.
UPDATE: On May 2018, about 50 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen to maintain a community-driven version called OpenAPI Generator. Please refer to the Q&A for more information.