2017-06-02 105 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