1

I'm having a problem with Swagger UI when trying to download a PDF file. Everything works fine outside Swagger UI (using curl or Postman there is no problem), but when I try to download via Swagger UI I get a blank PDF.

I'm using Springfox 2.50 (microservice JHipster application), and the response from my Java Spring method is a HttpEntity<byte[]>.

Edit: I found similar problem: Swagger UI Download PDF but it does not have any answers.

Community
  • 1
  • 1
apenlor
  • 87
  • 2
  • 15
  • @SurenSrapyan: Please don't use backticks `\`code\`` to format proper nouns, file extensions, etc. It's reserved for actual code - variable names, class names, etc. – Helen Jan 09 '17 at 13:20
  • I didn't do it. My post was edited by another user. – apenlor Jan 10 '17 at 13:35
  • Yes, my comment was addressed to the user who edited your post. – Helen Jan 10 '17 at 20:10

1 Answers1

0

You likely have one of the following issues with your setup:

1) The @produces on your server (and therefore in the swagger definition) may not be correct. Please make sure you have produces: application/pdf in your operation.

2) Your operation that returns the pdf may have no schema associated with it. For swagger-ui to render a proper download, you need to have a schema. The correct schema would be:

schema:
  type: string
  format: byte

3) Your server must be returning the correct Content-Type. Please make sure it's application/pdf in the headers

You might want to try the petstore sample against your server as that is the latest build of swagger-ui, the one bundled with SpringFox may be a bit behind.

fehguy
  • 6,724
  • 25
  • 23
  • 1
    1) I define in @RequestMapping the produces value. Still not working 2) How do I define the schema values with spring o swagger annotations? 3) Content-Type header is correct: "application/pdf" Thanks for your help – apenlor Jan 10 '17 at 15:32