editor.swagger.io上的编辑器将下面的Yaml呈现为类似于以下内容的json响应:
[
{
...
}
]
响应周围还有一组额外的括号,我觉得这可能会使我的前端团队感到困惑。这是正常现象吗,还是我的语法有问题?对不起,如果是不好的问题,还在学习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.
这是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
答案 0 :(得分:1)
您看到一个数组示例,因为响应定义为数组:
responses:
200:
description: successful foo
schema:
type: array # <-----
items:
$ref: '#/definitions/FooBar'
如果响应应该是单个对象,请将其更改为:
responses:
200:
description: successful foo
schema:
$ref: '#/definitions/FooBar'