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.8 Paths 对象
创建时间: 2025-05-29 16:38
4.8.8.1 模式化字段
字段模式类型描述
/{path}路径项对象到单个端点的相对路径。字段名称必须以正斜杠 (/) 开头。路径附加(无相对 URL 解析)到Server 对象的 url 字段中扩展的 URL 以构建完整 URL。路径模板是允许的。在匹配 URL 时,将先匹配具体的(非模板化的)路径,然后再匹配其模板化的对应路径。具有相同层次结构但不同模板名称的模板化路径不得存在,因为它们是相同的。在出现歧义匹配的情况下,由工具决定使用哪一个。

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

4.8.8.2 路径模板匹配

假设以下路径,如果使用具体的定义 /pets/mine,则将首先匹配它

  /pets/{petId}
  /pets/mine

以下路径被认为是相同的且无效的

  /pets/{petId}
  /pets/{name}

以下可能导致歧义解析

  /{entity}/me
  /books/{id}
4.8.8.3 Paths 对象示例
{
  "/pets": {
    "get": {
      "description": "Returns all pets from the system that the user has access to",
      "responses": {
        "200": {         
          "description": "A list of pets.",
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/pet"
                }
              }
            }
          }
        }
      }
    }
  }
}
/pets:
  get:
    description: Returns all pets from the system that the user has access to
    responses:
      '200':
        description: A list of pets.
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: '#/components/schemas/pet'
最后更新: -