SwaggerHub 编辑器在示例的最后和开头显示额外的数组括号?
SwaggerHub editor showing extra array brackets at the very end and beginning of the example?
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: [=12=].0
fb1: [=12=].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'
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: [=12=].0
fb1: [=12=].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'