Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify that a pdf is returned in swagger?

Tags:

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?

like image 750
Scottingham Avatar asked Aug 24 '15 16:08

Scottingham


People also ask

How do I set up Swagger documents?

Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to the right panel from the History section of Swagger Inspector, and click "Create API definition" to create the OAS definition.


2 Answers

  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.

like image 133
Ron Avatar answered Oct 07 '22 22:10

Ron


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

like image 38
nitashathakur Avatar answered Oct 07 '22 20:10

nitashathakur