2015-05-18 129 views
0

我必須維護一個使用Swagger來編碼api界面的項目。望着model.mustache,我看到:Swagger Codegen關鍵字添加

{{#models}}     
{{#model}}{{#description}} 
/**       
* {{description}}   
**/{{/description}}   

和像枚舉,默認值,乏,包等一堆其他關鍵字哪裏這些從何而來?我一直在搜索互聯網,試圖找到這方面的招搖會文件,但我找不到任何東西。引用github上的swagger信息的很多鏈接返回404頁。最後,我希望能夠做的是在我的實際.json文件中存在一個屬性,該文件是Swagger用來生成接口和模型以有條件地生成代碼的。我看到有這樣的if/else語句的表示法,但它不適用於我自己的.json的任何屬性。例如,在我的json中我有一個id字段。所以如果我想做一個人爲的例子

{{#id}}System.out.println(「test test」);{{/id}} 

將無法​​正常工作,因爲swagger不能識別id標籤。所以我的問題是,我可以添加這些標籤嗎?

回答

0

有很多工具可以幫助您。如果您看到錯誤的鏈接,請將問題提交至swagger-codegen項目。

從2.1.x-M1開始,swagger-codegen有一個非常有用的「調試」模式,可以讓您列出環境的所有可能值。可以按如下方式調用它:

java -DdebugModels -jar {path-to}/swagger-codegen-cli.jar generate {opts} 

支持的調試標誌是:

-DdebugModels: outputs the variables for each model discovered by codegen 
-DdebugOperations: outputs the variables for each operation 
-DdebugSupportingFiles: shows supporting file data (anything but models or operations) 
-DdebugSwagger: shows the parsed swagger representation 

我也看到,這些從README失蹤。將確保他們被添加。