Is it possible to configure the source code file header generated by swagger-codegen?

人走茶凉 提交于 2019-11-29 16:28:45

Yes it's possible. The output format is defined using Mustache templates.

Find the templates for your language here:
https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources

Download the templates you want to change and modify them as required. Then run the generator using the -t argument to specify the path to your custom templates:

java -jar swagger-codegen-cli-2-3-1.jar generate
  -i http://petstore.swagger.io/v2/swagger.json
  -l csharp
  -o PetstoreCSharpClient
  -t path/to/MyTemplates    <------

Any custom templates found in the -t folder will be used instead of the corresponding standard templates. Templates not found in the -t folder will default to the standard templates.

Example

In case of the csharp generator, the header in question comes from:

modules/swagger-codegen/src/main/resources/csharp/partial_header.mustache

and there are similar headers in:

modules/swagger-codegen/src/main/resources/csharp/Project.mustache
modules/swagger-codegen/src/main/resources/csharp/TestProject.mustache

Download these 3 files to, say, C:\MyTemplates, and remove unwanted lines from them. Then run the generator with -t C:\MyTemplates to use your custom templates without that header.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!