You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenAPI 3.x.x中如何为纯文本请求体添加示例?

在OpenAPI 3.x.x中给纯文本请求体加示例的正确方式

你之前的写法里,在text/plain的example下嵌套了value键,这是给JSON类型请求体加示例的逻辑,纯文本请求体不需要这么做——直接把示例字符串赋值给example字段就行。

修正后的YAML代码如下:

/path/to/api/:
  ... more properties
  requestBody:
    required: true
    content:
      text/plain:
        schema:
          $ref: '...path/to/schema'
        example: "hello"

只要你的schema已经定义了类型为string,这样配置后,示例就会显示为纯文本的"hello",不再是JSON对象格式。

如果需要添加多个示例,可以用复数形式的examples字段,写法参考:

/path/to/api/:
  ... more properties
  requestBody:
    required: true
    content:
      text/plain:
        schema:
          $ref: '...path/to/schema'
        examples:
          Sample1:
            value: "hello"
          Sample2:
            value: "world"

内容的提问来源于stack exchange,提问作者rohitt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 14:42:34