swagger codegen 在生成的文件中覆盖我的自定义代码 [英] swagger codegen is overwriting my custom code in generated files

查看:20
本文介绍了swagger codegen 在生成的文件中覆盖我的自定义代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 swagger codegen 来生成 jaxrs 服务器端类和客户端 java 类.

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();
  }

我在echo"方法中添加了魔法"并重新生成了代码,结果却发现它消失了.避免丢失自定义代码的一种方法是修改代码生成模板以生成接口而不是类.然后我可以在实现的类中拥有所有自定义代码.

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.

推荐答案

Swagger Codegen 最新大师 允许您在代码生成期间在 .swagger-codegen-ignore(类似于 .gitignore)中指定覆盖的文件.

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.

请拉取最新的 Swagger Codegen 大师来试一试.

Please pull the latest master of Swagger Codegen to give it a try.

更新:2018 年 5 月,大约 50 位 Swagger Codegen 的顶级贡献者和模板创建者决定分叉 Swagger Codegen 以维护一个名为 OpenAPI 生成器.请参阅问答了解更多信息.

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.

这篇关于swagger codegen 在生成的文件中覆盖我的自定义代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆