Reputation: 99
The editor on editor.swagger.io renders the below yaml to a json response that looks something like this:
[
{
...
}
]
There is an extra set of array brackets surrounding the response, which I feel may confuse my front end team. Is this normal, or what am I doing wrong with this syntax? Sorry if bad question, still learning yaml.
Yaml:
/getFoo:
get:
tags:
- Foo
summary: Finds foo
description: Get essential data specifically regarding the bar
operationId: getFooBar
produces:
- application/json
parameters:
- name: "foo"
in: "path"
description: Identifier used to retrieve foo bar.
required: true
type: "string"
responses:
200:
description: successful foo
schema:
type: array
items:
$ref: '#/definitions/FooBar'
400:
description: No foo found
500:
description: Internal server error.
This is what the definition for FooBar is:
FooBar:
type: object
properties:
foo:
type: string
example: "123"
bar:
type: object
example:
fb: $0.0
fb1: $0.0
baz:
type: array
items:
type: object
properties:
1:
type: string
example: 1
2:
type: string
example: 2
Upvotes: 0
Views: 407
Reputation: 97540
You see an array example because response is defined as array:
responses:
200:
description: successful foo
schema:
type: array # <-----
items:
$ref: '#/definitions/FooBar'
If the response is supposed to be a single object, change this to:
responses:
200:
description: successful foo
schema:
$ref: '#/definitions/FooBar'
Upvotes: 1