Swagger Codegen Selective Generation
You may not want to generate all models in your project. Likewise you may want just one or two apis to be written. If that’s the case, you can use system properties to control the output:
The default is generate everything supported by the specific library. Once you enable a feature, it will restrict the contents generated:
To control the specific files being generated, you can pass a CSV list of what you want:
To control generation of docs and tests for api and models, pass false to the option. For api, these options are -DapiTests=false
and -DapiDocs=false
. For models, -DmodelTests=false
and -DmodelDocs=false
.
These options default to true and don’t limit the generation of the feature options listed above (like -Dapi
):
When using selective generation, only the templates needed for the specific generation will be used.
Ignore file format
Swagger Codegen supports a .swagger-codegen-ignore
file, similar to .gitignore
or .dockerignore
you’re probably already familiar with.
The ignore file allows for better control over overwriting existing files than the --skip-overwrite
flag. With the ignore file, you can specify individual files or directories can be ignored. This can be useful, for example if you only want a subset of the generated code.
Examples:
The .swagger-codegen-ignore
file must exist in the root of the output directory.
Upon first code generation, you may also pass the CLI option --ignore-file-override=/path/to/ignore_file
for greater control over generated outputs. Note that this is a complete override, and will override the .swagger-codegen-ignore
file in an output directory when regenerating code.
Editor support for .swagger-codegen-ignore
files is available in IntelliJ via the .ignore plugin.