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}
使用選擇性生成時,只會使用特定生成所需的範本。