swagger-ui: Download link in response body does not work

I am having a problem similar to the ones described in #374 and #1196. I have a service which returns a pdf file as attachment with Content-Disposition header. This works when I call the endpoint from the browser - file is downloaded. On Swagger UI I get a download link after calling the service with response content type application/pdf, however that link downloads an empty pdf file:

swagger_pdf_download_doesnt_work

My swagger.json is generated by Enunciate (version 2.3.0) and the relevant part looks like this:

"responses": {
  "200": {
    "schema": {
    "description": "",
    "$ref": "#/definitions/json_File"
  }, ...

I tried adding "type": "file" to the schema, but it didn’t fix the problem. What could be going wrong here?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 33 (9 by maintainers)

Most upvoted comments

@fehguy ok I will show my backend java code also the swagger UI responses i get JAVA (server side): I am returning file and this would be a image, mp3, vedio, pdf, text etc

@GET
@Produces({MediaType.MULTIPART_FORM_DATA, MediaType.APPLICATION_OCTET_STREAM})
@ApiOperation(value = "Get Case Resource by resource Id")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success" })
@Path("attachment/{resourceId}")
public Response getCaseResource(@PathParam("resourceId") Long resourceId) {
 //........
return Response.status(Response.Status.OK).entity(file).header("Content-Disposition", "attachment ; filename=" + fileName).build();
}

swaggerui

On download this file, the file name is this as shown in the below image(which is not the actual file name) also the file gets corrupt. on_download

Also when i hit my server URL directly on the browser I get the exact file . please text if need any thing else?