【问题标题】:With drf-yasg, how can i show multiple openapi schemes?使用 drf-yasg,我如何显示多个 openapi 方案?
【发布时间】: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 重复这样的构造?

【问题讨论】:

    标签: python django drf-yasg


    【解决方案1】:

    不幸的是,这是不可能的。

    oneOf - 已添加到 OpenAPI 3.0,drf-yasg 仅支持 OpenAPI 2.0

    【讨论】:

      猜你喜欢
      • 2021-11-09
      • 2019-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      相关资源
      最近更新 更多