Swagger继承问题

时间:2015-12-23 07:44:12

标签: inheritance swagger swagger-2.0 swagger-editor

我在使用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"
            }
          }
        }
      ]
    }
  }
}

当我看到用户界面并单击"试试这个"时,我希望看到ExtendedErrorModel的字段。但是,我只看到以下不正确的内容:

如您所见,数据类型似乎是正确的。

enter image description here

但是,当您查看尝试此框时,您会注意到两个请求框(而不是一个),而ExtendedErrorModel是一个空白下拉框

enter image description here

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

任何建议表示赞赏, 谢谢, d

1 个答案:

答案 0 :(得分: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