How to add multiple example values ​​in my own right?

I use the Swagger OpenAPI Specification tool, I have a string array property in one of the definitions as follows:

cities:
        type: array
        items:
          type: string
          example: "Pune"

My API gives a JSON result, so for the above object, the following result appears in response:

{
  "cities": [
    "Pune"
  ]
}

Tried the lines separated by commas, as shown below:

cities:
            type: array
            items:
              type: string
              example: "Pune", "Mumbai", "Bangaluru"

Expected Result As:

{
      "cities": [
        "Pune",
        "Mumbai",
        "Bangaluru"
      ]
    }

But the editor shows an error. "Bad indentation"

I want to give a few values ​​to an example tag, is there a way?

Update

The Helen user below gave the correct answer. I had an indentaion problem, therefore there were nested arrays (2d arrays)

The right way:

cities:
        type: array
        items:
          type: string
        example: 
        - Pune
        - Mumbai

My way (what was wrong)

cities:
        type: array
        items:
          type: string
          example: 
          - Pune
          - Mumbai

Look for the indentation of the tag examplein the two previous cases, which makes the difference. Its YAML indentation matters.

+4
1

, example :

cities:
  type: array
  items:
    type: string
  example:
    - Pune
    - Mumbai
    - Bangaluru

  # or
  # example: [Pune, Mumbai, Bangaluru]
+2

Source: https://habr.com/ru/post/1686925/


All Articles