0

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 を表示して [Try This] をクリックすると、ExtendedErrorModel のフィールドが表示されるはずです。ただし、次のように表示されますが、これは正しくありません。

ご覧のとおり、データ型は正しいようです。

ここに画像の説明を入力

ただし、このボックスを試すと、(1 つではなく) 2 つの要求ボックスと、空のドロップダウン ボックスである ExtendedErrorModel に気付くでしょう。

ここに画像の説明を入力

サイト: http://editor.swagger.io/#/

アドバイスをいただければ幸いです、ありがとう、D

4

1 に答える 1

0

指定された定義は無効です:

  • タグ配列の後のコンマ"tags": ["Products"],
  • 応答がない

typeしかし、主な問題は、schema同時に使用できないことです。あなたは選ばなければなりません。

これらの問題を修正して を削除し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 に答える