How to get an image response in OpenApi Swagger 3.0

Viewed 2444

I have an endpoint which returns an image in response and I would like the swagger documentation to return and display the image within the framework. I've looked at the documentation here and here and tried all three examples all which have no success. Am I trying the impossible?

Here is my example

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

The generated curl also warns about binary output

1 Answers

Change application/png to image/png. Other than that, your definition is correct.

Related