我通过 SwaggerHub 设置了新的 OpenAPI。是否有一个选项可以强制执行某些操作Accept
全局标题?
我已经设置了Content-Type
关于回应:
openapi: 3.0.0
paths:
/test-path:
get:
responses:
'200':
description: OK
content:
application/vnd.company.v1.0.0+json:
当插入不同的Accept
通过 cURL 请求标头,生成以下内容:
{"message":"Missing matching response for specified Accept header"}
这是有道理的,因为我们没有对此做出任何回应。
与 OpenAPI/Swagger 2.0 不同,它具有global consumes and produces https://stackoverflow.com/q/45484702/113116,OpenAPI 3.0 要求在每个操作中单独定义请求和响应媒体类型。没有办法定义Content-Type
或全球范围内的请求或响应。
但是,您可以$ref
共同的响应定义(例如错误响应),可以减少重复。
openapi: 3.0.2
...
paths:
/foo:
get:
responses:
'400':
$ref: '#/components/responses/ErrorResponse'
/bar:
get:
responses:
'400':
$ref: '#/components/responses/ErrorResponse'
components:
responses:
ErrorResponse:
description: An error occurred
content:
application/vnd.error+json:
schema:
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)