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
相关产品推荐
相关产品推荐

