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