Swagger Codegen 选择性生成
您可能不想在项目中生成所有模型。同样,您可能只想编写一个或两个 API。如果是这种情况,您可以使用系统属性来控制输出
默认是生成特定库支持的所有内容。启用某项功能后,它将限制生成的内容
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
要控制生成的特定文件,您可以传递您需要的 CSV 列表
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
要控制 api 和模型的文档和测试的生成,请将 false 传递给该选项。对于 api,这些选项是 -DapiTests=false
和 -DapiDocs=false
。对于模型,则是 -DmodelTests=false
和 -DmodelDocs=false
。这些选项默认为 true,并且不限制上面列出的功能选项的生成(如 -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}
当使用选择性生成时,仅会使用特定生成所需的模板。