1

I am writing an OpenAPI 3.0 specification and have an endpoint returning a file. Now I found documentation on the website of Swagger but that's about a POST request: https://swagger.io/docs/specification/describing-request-body/multipart-requests/.

There's also another StackOverflow question with zero responses about my question, so I will give it another go.

How does one write a specification for a GET request where a file should be returned?

I currently have the following:

      responses:
        '200':
          description: ok
          content:
            multipart/form-data:
              schema:
                type: object
                description: The multipart object containing the file bytes
                properties:
                  file:
                    type: string
                    format: binary
                    description: Bytes of the file

But I think this is mostly for POST request, to upload a file. Does anyone know what it should be?

Ricardo de Vries
  • 113
  • 3
  • 11

1 Answers1

1

In OpenAPI 3.0, a response containing a PDF, PNG, or JPG file is described as follows:

      responses:
        '200':
          description: A PDF file, PNG image, or JPG image
          content:
            application/pdf:
              schema:
                type: string
                format: binary
            image/png:
              schema:
                type: string
                format: binary
            image/jpeg:  # 'jpeg' not 'jpg', see https://stackoverflow.com/q/33692835
              schema:
                type: string
                format: binary
Helen
  • 87,344
  • 17
  • 243
  • 314