Swagger Codegenの選択的生成
プロジェクト内の「すべての」モデルを生成したくない場合があります。同様に、1つか2つの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}
選択的生成を使用する場合、特定の生成に必要なテンプレート「のみ」が使用されます。