0

我在使用带有招摇的继承时遇到问题。我有以下内容:

{
    "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 的字段。但是,我只看到以下不正确的内容:

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

在此处输入图像描述

但是,当您查看 try this 框时,您会注意到两个请求框(而不是一个)并且 ExtendedErrorModel 是一个空白下拉框

在此处输入图像描述

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

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

4

1 回答 1

0

提供的定义无效:

  • 标签数组后的逗号"tags": ["Products"],
  • 缺少响应

但主要问题是你不能同时使用typeschema。你必须选择。

在更正这些问题并删除type:''后,编辑认为规范是有效的。

在此处输入图像描述

但是 editor.swagger.io 的在线编辑器并没有显示所有参数:

参数输入

如果您尝试在https://swaggerhub.com上运行它:

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
于 2016-05-16T17:28:22.310 回答