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 example
in the two previous cases, which makes the difference. Its YAML indentation matters.