Skip to content

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:

Terminal window
1
# generate only models
2
java -Dmodels {opts}
3
4
# generate only apis
5
java -Dapis {opts}
6
7
# generate only supporting files
8
java -DsupportingFiles
9
10
# generate models and supporting files
11
java -Dmodels -DsupportingFiles

To control the specific files being generated, you can pass a CSV list of what you want:

Terminal window
1
# generate the User and Pet models only
2
-Dmodels=User,Pet
3
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):

Terminal window
1
# generate only models (with tests and documentation)
2
java -Dmodels {opts}
3
4
# generate only models (with tests but no documentation)
5
java -Dmodels -DmodelDocs=false {opts}
6
7
# generate only User and Pet models (no tests and no documentation)
8
java -Dmodels=User,Pet -DmodelTests=false {opts}
9
10
# generate only apis (without tests)
11
java -Dapis -DapiTests=false {opts}
12
13
# generate only apis (modelTests option is ignored)
14
java -Dapis -DmodelTests=false {opts}

When using selective generation, only the templates needed for the specific generation will be used.