I can do this:
我可以这样做:
parameters:
avatarSizeParam:
name: size
in: query
description: Size of avatar.
enum: [32, 64]
required: false
type: integer
format: int32
paths:
/my/path/avatar:
get:
parameters:
- $ref: '#/parameters/avatarSizeParam'
Good. Swagger defines a parameters
key where you can define Parameter Objects
to be reused. It also defines a responses
key, where you can define Response Objects
like so:
好。Swagger定义了一个参数键,您可以在其中定义要重用的参数对象。它还定义了一个响应键,您可以在其中定义响应对象如下:
responses:
notFoundResponse:
description: Entity not found.
schema:
$ref: '#/definitions/schema404'
So I assumed I could expand my previous path definition to the following
我假设我可以把之前的路径定义扩展到下面
paths:
/my/path/avatar:
get:
parameters:
- $ref: '#/parameters/avatarSizeParam'
responses:
- $ref: '#/responses/notFound'
This doesn't seem to work however. I went back to the spec for an Operations Object
and noticed that parameters
can be a Reference Object, but responses
cannot.
然而,这似乎行不通。我返回到一个操作对象的规范,并注意到参数可以是一个引用对象,但是响应不能。
What is the point of allowing a Responses Definitions Object (responses
on the top-most level) if you can't reference the items there? Is there a way to do so?
如果您不能引用那里的项,那么允许一个响应定义对象(最顶层的响应)有什么意义呢?有办法这么做吗?
1 个解决方案
#1
16
If you see here, you have to define HTTP Status Code as a key, then the correct syntax is:
如果您在这里看到,您必须将HTTP状态代码定义为键,那么正确的语法是:
paths:
/my/path/avatar:
get:
parameters:
- $ref: '#/parameters/avatarSizeParam'
responses:
404:
$ref: '#/responses/notFound'
#1
16
If you see here, you have to define HTTP Status Code as a key, then the correct syntax is:
如果您在这里看到,您必须将HTTP状态代码定义为键,那么正确的语法是:
paths:
/my/path/avatar:
get:
parameters:
- $ref: '#/parameters/avatarSizeParam'
responses:
404:
$ref: '#/responses/notFound'