OpenAPI 规范 v3.1.0
OpenAPI 规范 v3.1.0
1. OpenAPI 规范
2. 简介
3. 定义
4. 规范
4.1 版本
4.2 格式
4.3 文档结构
4.4 数据类型
4.5 富文本格式化
4.6 URI 中的相对引用
4.7 URL 中的相对引用
4.8 模式
4.9 规范扩展
4.10 安全过滤
4.8.17 Response 对象
创建时间: 2025-05-29 16:38

描述来自 API 操作的单个响应,包括基于响应的操作的设计时静态 链接

4.8.17.1 固定字段
字段名称类型描述
description字符串必需。响应的描述。[CommonMark] 语法可以用于富文本表示。
headersMap[string头部对象  引用对象]将标头名称映射到其定义。[RFC7230第 22 页 指出标头名称不区分大小写。如果使用名称 "Content-Type" 定义了响应标头,则必须忽略它。
contentMap[string媒体类型对象]包含潜在响应有效负载描述的地图。键是媒体类型或媒体类型范围,请参阅[RFC7231附录 D,其值描述了它。对于匹配多个键的响应,只有最具体的键适用。例如,text/plain 覆盖 text/*。
链接Map[string链接对象  引用对象]可以从响应中跟随的操作链接的映射。映射的键是链接的简称,遵循组件对象名称的命名约束。

此对象*可以使用 规范扩展 进行扩展。

*4.8.17.2 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
content:
  text/plain:
    schema:
      type: string

带有标头的纯文本响应

{
  "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: 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
最后更新: -