【发布时间】:2022-12-06 21:10:21
【问题描述】:
使用:Django 2.2, drf-yasg 1.17.1, python 3.9
如何使用 drf-yasg 显示多个 openapi 方案?
API 返回不同的响应,具体取决于请求。
基本回应:
是否有可能在 drf-yasg 中显示这样的响应?
在 yaml 文件中,这是使用 oneOf 实现的。
代码示例:
responses:
'200':
content:
application/json:
schema:
properties:
count:
type: integer
next:
type: string
previous:
type: string
results:
oneOf:
- $ref: '#/components/schemas/BaseStocks'
- $ref: '#/components/schemas/Apteka36.6Stocks'
- $ref: '#/components/schemas/FarmiyaStocks'
- $ref: '#/components/schemas/MailruStocks'
- $ref: '#/components/schemas/NeofarmStocks'
- $ref: '#/components/schemas/YandexStock'
- $ref: '#/components/schemas/UtekaStocks'
是否可以用 drf-yasg 重复这样的构造?
【问题讨论】: