如何在 OpenApi Swagger 3.0 中获取图像响应

And*_*ndy 8 swagger openapi

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

这是我的例子

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
Run Code Online (Sandbox Code Playgroud)

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

Hel*_*len 9

改成。application/pngimage/png除此之外,你的定义是正确的。