【问题标题】:How to get an image response in OpenApi Swagger 3.0如何在 OpenApi Swagger 3.0 中获得图像响应
【发布时间】:2021-05-31 05:32:46
【问题描述】:

我有一个端点,它返回一个图像作为响应,我希望 swagger 文档返回并在框架内显示图像。 我查看了文档here 和here 并尝试了所有三个示例都没有成功。 我在尝试不可能的事情吗?

这是我的例子

paths:
   "/qrcodes/{string_to_encode}":
    get:
      tags:
        - QR Code
      summary: A QR code generation endpoint
      parameters:
        - name: string_to_encode
          in: path
          required: true
          description: URL encoded string to convert to a QR code
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
              application/png:
                schema: 
                  type: string
                  format: binary

生成的 curl 还会警告二进制输出

【问题讨论】:

    标签: swagger openapi


    【解决方案1】:

    将application/png 更改为image/png。除此之外,您的定义是正确的。

    【讨论】:

      猜你喜欢
      • 2021-11-23
      • 1970-01-01
      • 2020-05-09
      • 2020-02-26
      • 2021-12-22
      • 2019-07-23
      • 1970-01-01
      • 2021-01-20
      相关资源
      最近更新 更多