问题
I am using swagger-codegen to generate a SDK based on my Web API, and the generated source files contains the following header:
/*
* [MY PROJECT NAME]
*
* [MY COPYRIGHT]
*
* OpenAPI spec version: 1.0.0 - Beta
* Contact: [MY EMAIL]
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*/
Would it be possible to configure swagger-codegen to not generate the last 3 lines of the header?
回答1:
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.
来源:https://stackoverflow.com/questions/50165530/is-it-possible-to-configure-the-source-code-file-header-generated-by-swagger-cod