Codegen is overwriting my code

33 views
Skip to first unread message

nikhil...@gmail.com

unread,
Mar 25, 2015, 6:07:19 AM3/25/15
to swagger-sw...@googlegroups.com
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.


tony tam

unread,
Mar 26, 2015, 12:34:32 PM3/26/15
to swagger-sw...@googlegroups.com
The intention is that you modify the templates to your own workflow & liking.  We are addressing this with configurations--please open a ticket in swagger-codegen so you can follow it.
Reply all
Reply to author
Forward
0 new messages