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:
1# generate only models2java -Dmodels {opts}3
4# generate only apis5java -Dapis {opts}6
7# generate only supporting files8java -DsupportingFiles9
10# generate models and supporting files11java -Dmodels -DsupportingFiles
To control the specific files being generated, you can pass a CSV list of what you want:
1# generate the User and Pet models only2-Dmodels=User,Pet3
4# generate the User model and the supportingFile `StringUtil.java`:5-Dmodels=User -DsupportingFiles=StringUtil.java
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
):
1# generate only models (with tests and documentation)2java -Dmodels {opts}3
4# generate only models (with tests but no documentation)5java -Dmodels -DmodelDocs=false {opts}6
7# generate only User and Pet models (no tests and no documentation)8java -Dmodels=User,Pet -DmodelTests=false {opts}9
10# generate only apis (without tests)11java -Dapis -DapiTests=false {opts}12
13# generate only apis (modelTests option is ignored)14java -Dapis -DmodelTests=false {opts}
When using selective generation, only the templates needed for the specific generation will be used.