Swagger Yaml 缩进问题

Swagger Yaml indentation issue

我正在为我的第一个 YAML for swagger 寻求帮助,我不知道如何修复它,我想了解问题所在 - 代码工作正常,但代码中的错误标记不正确对我来说。

所以这里是错误的截图:

这是可见的问题:

代码如下:

    swagger: '2.0'
info:
  version: '1.0'
  title: NBP Exchange rates
  description: 'Get exchnagarate from NBP'
# Added by API Auto Mocking Plugin
host: api.nbp.pl
basePath: /api
schemes:
 - http
consumes: 
  - application/json
produces: 
  - application/json
paths: 
 /exchangerates/rates/{table}/{currency}/{Date}:
    get:
      summary: get exchange rate
      parameters:
      - name: table
        type: string
        in: path
        required: true
        description: table of exchange rate A,B or C
      - name: currency
        type: string
        in: path
        required: true
        #desctription: Currency 3 letter code
      - name: Date
        type: string
        in: path
        required: true
        #desctription: Date on which you want to check exchange rate
      responses:
            '200':
              description: Exchange rate for your query
            schema:
              type: object
              properties: 
                table: 
                  type: string
                currency: 
                  type: string
                code: 
                  type: string
                rates: 
                  type: array
                  items: 
                      type: object
                      properties: 
                        no: 
                          type: string
                        effectiveDate: 
                          type: string
                        bid: 
                          type: number
                        ask: 
                          type: number
                  required: [no,effectiveDate,bid,ask]
              required: [table,currency,code,rates]
            '400':
              description: Bad request. User ID must be an integer and larger than 0.
            '401':
              description: Authorization information is missing or invalid.
            '404':
              description: A user with the specified ID was not found.
            '5XX':
              description: Unexpected error

.

我该如何解决:(?

schema 关键字必须位于响应代码“内部”(在本例中为 200),如下所示:

      responses:
            '200':
              description: Exchange rate for your query
              schema:
                type: object
                properties: 
                  table: 
                    type: string
                  currency: 
                    type: string
                  code: 
                    type: string
                  rates: 
                    type: array
                    items: 
                        type: object
                        properties: 
                          'no':    # <----- Add quotes around 'no'
                            type: string
                          effectiveDate: 
                            type: string
                          bid: 
                            type: number
                          ask: 
                            type: number
                        required: ['no',effectiveDate,bid,ask]    # <----- Add quotes around 'no'
                required: [table,currency,code,rates]

此代码段还修复了架构中的其他缩进问题。

其他说明:

  • 属性名称no必须用引号括起来,否则某些工具可能会将其解析为YAML boolean value false.
  • OpenAPI 2.0 不支持像 5XX 这样的响应范围,它只支持像 '500' 这样的特定代码。