跳至內容

Swagger Codegen 選擇性生成

您可能不想在專案中產生所有模型。同樣地,您可能只想寫入一兩個 API。如果這樣,您可以使用系統屬性來控制輸出

預設是產生特定程式庫支援的所有內容。一旦啟用功能,它將限制產生的內容

終端機視窗
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

要控制產生的特定檔案,您可以傳遞您想要的 CSV 清單

終端機視窗
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

若要控制 API 和模型的檔案和測試生成,請將 false 傳遞給該選項。對於 API,這些選項為 -DapiTests=false-DapiDocs=false。對於模型,-DmodelTests=false-DmodelDocs=false。這些選項預設為 true,且不會限制上面列出的功能選項的生成(例如 -Dapi

終端機視窗
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}

使用選擇性生成時,只會使用特定生成所需的範本。