【发布时间】:2018-10-28 01:48:06
【问题描述】:
我想做的是指定有时对 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"
OAS3 文档 (https://swagger.io/docs/specification/describing-responses/) 提供了以下示例,说明如何指定几种不同 JSON 模式之一可能是对特定 API 调用的响应。这几乎是我想要的,除了描述不同的可能 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'
【问题讨论】:
标签: openapi