Search code examples
yamlswaggerswagger-2.0

Swagger Yaml indentation issue


I'm looking for help with my first YAML for swagger, I have no idea how to fix it and I would like to learn what is wrong - code is working fine but this error mark in the code is not ok for me.

So here is the screenshot of the error: enter image description here

and here is the issue visible issue:

enter image description here

Here is the code:

    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

.

How can I fix it :(?


Solution

  • The schema keyword must be "inside" the response code (in this case 200), like so:

          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]
    

    This snippet also fixes other indentation issues in the schema.

    Other notes:

    • The property name no must be enclosed in quotes, otherwise some tools may parse it as YAML boolean value false.
    • OpenAPI 2.0 does not support response ranges like 5XX, it only supports specific codes like '500'.