2017-06-02 55 views
0

生成服務器代碼中使用this minimal examplespringjaxrs-spec創建2分模型類爲:Pet.javaInlineResposne200.java。除了班級名稱,他們是相同的。揚鞭生成複製模型類

,響應/pets回報List<InlineResponse200>代替List<Pet>和類Pet實際上從來沒有在任何地方使用,即使YAML定義使用$ref: "#/definitions/Pet"控制器。這是爲什麼發生?

--- 
    swagger: "2.0" 
    info: 
    version: "1.0.0" 
    title: "Swagger Petstore" 
    description: "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification" 
    termsOfService: "http://swagger.io/terms/" 
    contact: 
     name: "Swagger API Team" 
    license: 
     name: "MIT" 
    host: "petstore.swagger.io" 
    basePath: "/api" 
    schemes: 
    - "http" 
    consumes: 
    - "application/json" 
    produces: 
    - "application/json" 
    paths: 
    /pets: 
     get: 
     description: "Returns all pets from the system that the user has access to" 
     produces: 
      - "application/json" 
     responses: 
      "200": 
      description: "A list of pets." 
      schema: 
       type: "array" 
       items: 
       $ref: "#/definitions/Pet" 
    definitions: 
    Pet: 
     type: "object" 
     required: 
     - "id" 
     - "name" 
     properties: 
     id: 
      type: "integer" 
      format: "int64" 
     name: 
      type: "string" 
     tag: 
      type: "string" 

回答

1

我試圖複製這種與swagger-codegen v2.2.2同時使用springjaxrs-spec,但我沒能拿到InlineResponse200.java

但是,做了一些更多的挖掘,我發現這個問題最近是reported作爲一個錯誤。它尚未修復,但InlineResponse200.java並不意味着在那裏。

當使用Swagger Editor v3時,此文件似乎不正確地生成。我猜這就是你如何生成你的文件?

雖然Swagger Editor v2沒有這個問題,我暫時的建議是安裝和使用最新的穩定版本swagger-codegen從您的Swagger.yaml文件生成您的代碼。

希望這會有所幫助。

+0

從我的機器生成使用v2.2.2工作正常,謝謝!我使用'http:// editor.swagger.io'上的那個 – cahen