SwaggerHub 编辑器在示例的最后和开头显示额外的数组括号?



editor.swagger.io 上的编辑器将以下yaml呈现为如下所示的json响应:

[
{
...
}
]

响应周围有一组额外的数组括号,我觉得这可能会让我的前端团队感到困惑。这是正常的,还是我用这种语法做错了什么?对不起,如果问题不好,还在学习 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.

这就是FooBar的定义:

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

您会看到一个数组示例,因为响应被定义为数组:

responses:
200:
description: successful foo
schema:
type: array   # <-----
items:
$ref: '#/definitions/FooBar'

如果响应应该是单个对象,请将其更改为:

responses:
200:
description: successful foo
schema:
$ref: '#/definitions/FooBar'