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.19 Example 对象
创建时间: 2025-05-29 16:38
4.8.19.1 固定字段
字段名称类型描述
摘要字符串示例的简短描述。
描述字符串示例的详细描述。[CommonMark] 语法可以用于富文本表示。
任何嵌入的文字示例。value字段和externalValue字段是互斥的。要表示无法以 JSON 或 YAML 自然表示的媒体类型的示例,请使用字符串值包含示例,并在必要时进行转义。
外部值字符串指向文字示例的 URI。这提供了引用无法轻松包含在 JSON 或 YAML 文档中的示例的功能。value字段和externalValue字段是互斥的。请参阅解析相对引用的规则。

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

在所有情况下,示例值都应与其关联值的类型模式兼容。工具实现可以选择自动验证兼容性,并在不兼容时拒绝示例值。

4.8.19.2 Example 对象示例

在请求主体中

requestBody:
  content:
    'application/json':
      schema:
        $ref: '#/components/schemas/Address'
      examples:
        foo:
          summary: A foo example
          value: {"foo": "bar"}
        bar:
          summary: A bar example
          value: {"bar": "baz"}
    'application/xml':
      examples:
        xmlExample:
          summary: This is an example in XML
          externalValue: 'https://example.org/examples/address-example.xml'
    'text/plain':
      examples:
        textExample:
          summary: This is a text example
          externalValue: 'https://foo.bar/examples/address-example.txt'

在参数中

parameters:
  - name: 'zipCode'
    in: 'query'
    schema:
      type: 'string'
      format: 'zip-code'
    examples:
      zip-example:
        $ref: '#/components/examples/zip-example'

在响应中

responses:
  '200':
    description: your car appointment has been booked
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/SuccessResponse'
        examples:
          confirmation-success:
            $ref: '#/components/examples/confirmation-success'
最后更新: -