2015-12-23 62 views
0

我遇到了使用繼承與swagger的問題。我有以下內容:Swagger繼承問題

{ 
    "swagger": "2.0", 
    "info": { 
     "title": "Uber API", 
     "description": "Move your app forward with the Uber API", 
     "version": "1.0.0" 
    }, 
    "host": "api.uber.com", 
    "schemes": [ 
     "https" 
    ], 
    "basePath": "/v1", 
    "produces": [ 
     "application/json" 
    ], 
    "paths": { 
     "/products": { 
      "post": { 
       "summary": "Product Types", 
       "description": "The Products endpoint returns information about the *Uber* products\noffered at a given location. The response includes the display name\nand other details about each product, and lists the products in the\nproper display order.\n", 
       "parameters": [ 
        { 
         "name": "error", 
         "in": "body", 
         "description": "Latitude component of location.", 
         "required": true, 
         "type": "", 
         "schema": { 
          "$ref": "#/definitions/ExtendedErrorModel" 
         } 
        } 

       ], 
       "tags": [ 
        "Products" 
       ], 

      } 
     } 
    }, 

    "definitions": { 
    "ErrorModel": { 
     "type": "object", 
     "required": [ 
     "message", 
     "code" 
     ], 
     "properties": { 
     "message": { 
      "type": "string" 
     }, 
     "code": { 
      "type": "integer", 
      "minimum": 100, 
      "maximum": 600 
     } 
     } 
    }, 
    "ExtendedErrorModel": { 
     "allOf": [ 
     { 
      "$ref": "#/definitions/ErrorModel" 
     }, 
     { 
      "type": "object", 
      "required": [ 
      "rootCause" 
      ], 
      "properties": { 
      "rootCause": { 
       "type": "string" 
      } 
      } 
     } 
     ] 
    } 
    } 
} 

當我看到UI並單擊「試試這個」時,我希望看到ExtendedErrorModel的字段。但是,我只看到以下不正確的內容:

正如您所看到的,數據類型似乎是正確的。

enter image description here

但是,當你看看試試這個盒子,你會發現兩個要求箱(而不是一個)和ExtendedErrorModel是一個空白的下拉框

enter image description here

網站: http://editor.swagger.io/#/

任何意見理解, 謝謝, d

回答

0

提供的定義是無效的:

後標籤陣列 "tags": ["Products"],
  • 缺少響應
  • 但主要問題

    • 逗號,你不能在同一時間使用typeschema 。你必須選擇。

      糾正這些問題並刪除type:''後,編輯認爲該規範有效。

      enter image description here

      但在editor.swagger.io的在線編輯器不顯示所有的參數:

      Parameters input

      如果你嘗試https://swaggerhub.com它的工作原理:

      Paramaters input on swaggerhub.com

      更正的規格:

      swagger: '2.0' 
      info: 
          title: Uber API 
          description: Move your app forward with the Uber API 
          version: 1.0.0 
      host: api.uber.com 
      schemes: 
          - https 
      basePath: /v1 
      produces: 
          - application/json 
      paths: 
          /products: 
          post: 
           summary: Product Types 
           description: | 
           The Products endpoint returns information about the *Uber* products 
           offered at a given location. The response includes the display name 
           and other details about each product, and lists the products in the 
           proper display order. 
           parameters: 
           - name: error 
            in: body 
            description: Latitude component of location. 
            required: true 
            schema: 
            $ref: '#/definitions/ExtendedErrorModel' 
           tags: 
           - Products 
           responses: 
           200: 
            description: OK 
      definitions: 
          ErrorModel: 
          type: object 
          required: 
           - message 
           - code 
          properties: 
           message: 
           type: string 
           code: 
           type: integer 
           minimum: 100 
           maximum: 600 
          ExtendedErrorModel: 
          allOf: 
           - $ref: '#/definitions/ErrorModel' 
           - type: object 
           required: 
            - rootCause 
           properties: 
            rootCause: 
            type: string