跳转到主要内容
如果你的 API 会根据输入参数、用户上下文或请求的其他条件返回不同的响应,你可以使用 examples 属性来记录多个响应示例。 将此属性添加到任意响应中。它具有以下架构。
responses:
  "200":
    description: 成功响应
    content:
      application/json:
        schema:
          $ref: "#/components/schemas/YourResponseSchema"
        examples:
          us:
            summary: 美国的响应
            value:
              countryCode: "US"
              currencyCode: "USD"
              taxRate: 0.0825
          gb:
            summary: 英国的响应
            value:
              countryCode: "GB"
              currencyCode: "GBP"
              taxRate: 0.20
Playground 还会根据内容类型,以不同方式处理非 JSON 响应。

音频响应示例

对于返回音频文件的端点,请将响应内容类型设置为 audio/*,并提供音频文件的 URL 作为示例值。playground 显示的是交互式音频播放器,而不是代码片段。
responses:
  "200":
    description: Audio file generated successfully
    content:
      audio/mpeg:
        schema:
          type: string
          format: binary
        examples:
          sample:
            summary: Sample audio output
            value: "https://example.com/sample-audio.mp3"