Swagger/OpenAPI definition:
/pdf/{date}/lunch.pdf:
get:
tags:
- PDF
summary: Mittagessen als PDF (Woche)
parameters:
- name: date
in: path
description: YYYY-MM-DD
required: true
schema:
type: string
responses:
'200':
description: OK
headers:
Content-Disposition:
schema:
type: string
example: filename=\lunch.pdf\
content:
application/pdf:
schema:
type: string
format: binary
example: PDF-Datei
When you are calling an API in the try it out-section which returns an PDF-File the response body is not able to render the file or present it in a readable format. Instead you get the following message: Unrecognized response type; displaying content as text. - even if the correct content type is passed in the response header (Screenshot HTTP Request-Response).
Additionally the binary data will be displayed in the response body. (Screenshot Swagger-UI)
Steps to reproduce the behavior:
In Swagger-UI
The PDF should be rendered as an typical pdf file in the swagger-ui or you should provide a download link to extract the file.
HTTP Request-Response
Swagger-UI Display
Unfortunatly i cannot provide a running API which returns a valid PDF-File to debugging this issue
Whenever you run the command
curl -X GET "http://server.de/menupdfservice/api/pdf/pdf/2019-07-26/lunch.pdf" -H "accept: application/json
which the Swagger-UI is calling outside of Swagger-UI you get the binary data as well.
But when you try to merge this data with
curl -X GET "http://server.de/menupdfservice/api/pdf/pdf/2019-07-26/lunch.pdf" -H "accept: application/json --output lunch.pdf
in a spefic file with extension you get a properly working PDF-file
@fabieu have you solved that?
@fabieu have you solved that?
Actually not, but I was tired dealing with this issue
Same here. I'm using swagger-jsdoc and face this issue. My endpoint:
/**
* @swagger
*
* /pdf:
* post:
* description: Get PDF
* produces:
* - application/pdf
* parameters:
* - in: body
* name: orderIds
* description: order ids
* schema:
* type: array
* items:
* type: string
* format: guid
* responses:
* 200:
* description: A PDF file
* content:
* application/pdf:
* schema:
* type: file
* format: binary
*/
In the end it worked when I added headers to the response:
res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename=labels.pdf');
Same problem here, and besides that, The serialized string has encoding issue.
If I test from browser or JAVA client, the PDF response is correct.
Sounds to be an issue on swagger-ui to render/serialize PDF files,
Most helpful comment
In the end it worked when I added headers to the response: