我想要做的是指定API调用的响应有时可能是PDF文档,有时可能是JSON。我想用OpenAPI 3.0格式做这件事。对于PDF,响应将如下所示:
responses:
'200':
description: An invoice in PDF format.
content:
application/pdf:
schema:
type: string
format: binary在JSON响应的情况下,这将描述响应:
responses:
'200':
description: A JSON object containing user name and avatar
content:
application/json:
schema:
$ref: "#/components/schemas/Invoice" JSON (https://swagger.io/docs/specification/describing-responses/)提供了以下示例,说明如何指定几个不同的JSON中的一个可以作为对特定OAS3调用的响应。这几乎就是我想要的,除了不描述不同可能的JSON模式之外,我想指定不同的可能的内容类型,如上所述。有没有办法在OAS3格式中做到这一点?
responses:
'200':
description: A JSON object containing pet information
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Hamster'发布于 2018-05-18 01:40:48
我发现这是可行的:
responses:
'200':
description: "An invoice."
content:
application/json:
schema:
$ref: "#/components/schemas/Invoice"
application/pdf:
schema:
type: "string"
format: "binary"请参阅此处的“响应媒体类型”部分:https://swagger.io/docs/specification/describing-responses/
https://stackoverflow.com/questions/50397427
复制相似问题