跳到主要内容

Response 对象

描述单个 API 操作的响应,包括设计时间、基于不同响应也包括到相应操作的静态 links

固定字段

字段名类型描述
descriptionstring必选. 对响应的简短描述。CommonMark syntax可以被用来呈现富文本格式.
headersMap[string, Header 对象 |Reference 对象]映射 HTTP 头名称到其定义。RFC7230 规定了 HTTP 头名称不区分大小写。如果一个响应头使用"Content-Type"作为 HTTP 头名称,它会被忽略。
contentMap[string, Media Type 对象]一个包含描述预期响应负载的映射。使用 media type 或 media type range 作为键,以响应的描述作为值。当一个响应匹配多个键时,只有最明确的键才适用。比如:text/plain 会覆盖 text/*
linksMap[string, Link 对象 | Reference 对象]A map of operations links that can be followed from the response. The key of the map is a short name for the link,following the naming constraints of the names for Component 对象.

这个对象可能会被规范扩展扩展。

Response 对象示例

一个包含复杂类型的数组格式的响应:

{
"description": "A complex object array response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/VeryComplexType"
}
}
}
}
}
description: A complex object array response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/VeryComplexType'

字符串类型的响应:

{
"description": "A simple string response",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
description: A simple string response
representations:
text/plain:
schema:
type: string

带 HTTP 头的普通文本类型的响应:

{
"description": "A simple string response",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
},
"headers": {
"X-Rate-Limit-Limit": {
"description": "The number of allowed requests in the current period",
"schema": {
"type": "integer"
}
},
"X-Rate-Limit-Remaining": {
"description": "The number of remaining requests in the current period",
"schema": {
"type": "integer"
}
},
"X-Rate-Limit-Reset": {
"description": "The number of seconds left in the current period",
"schema": {
"type": "integer"
}
}
}
}
description: A simple string response
content:
text/plain:
schema:
type: string
example: 'whoa!'
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
schema:
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
schema:
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
schema:
type: integer

没有返回值的响应:

{
"description": "object created"
}
description: object created