32

I have a get call in my swagger REST API that needs to return a pdf file. There is no clear example / documentation on how to do this without causing a syntax error.

  responses:
    200:
      description: Returns PDF
      schema: [application/pdf]

and

  responses:
    200:
      description: Returns PDF
      schema: 
        type: file

and

  responses:
    200:
      description: Returns PDF
      schema:
        type:  [application/pdf]

all fail. Is this even possible?

Scottingham
  • 906
  • 2
  • 11
  • 26

2 Answers2

24
  responses:
    200:
      description: Returns PDF
      schema: 
        type: file

Out of the options you gave, that's the right option. Also, make sure to use produces: [application/pdf]

If it fails for you, make sure you use the latest version of the editor. There was a bug related to the file type that was recently resolved.

Ron
  • 14,160
  • 3
  • 52
  • 39
  • 5
    With Open API 3.0 , try below `responses: '200': description: A PDF file content: application/pdf: schema: type: string format: binary` Documentation: https://swagger.io/docs/specification/describing-responses/ Section:Response That Returns a File – nitashathakur Feb 20 '20 at 00:58
  • 2
    @dev1918 you should post it as another answer. – Innokenty Sep 02 '21 at 14:32
22

With Open API 3.0 ,try below responses:

get:
  summary: Returns the report in the PDF format
  responses:
    '200':
      description: A PDF file
      content:
        application/pdf:
          schema:
            type: string
            format: binary

Documentation: swagger.io/docs/specification/describing-responses

Section: Response That Returns a File

nitashathakur
  • 430
  • 3
  • 9