3

I am having a problem similar to the ones described here and here. 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:

enter image description here

Note that 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 this, but it didn't fix the problem. What could be going wrong here?

Egemen
  • 2,178
  • 5
  • 22
  • 32

1 Answers1

2

You can document the return type of the response (200) as binary (format) instead:

  responses:
    '200':
      description: successful operation
      schema:
        type: string
        format: binary

According to the spec, "binary" (format) refers to "any sequence of octets "

Ref: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types

William Cheng
  • 10,137
  • 5
  • 54
  • 79
  • I tried it, but I am still having the same issue. According to the last comment [here](https://github.com/swagger-api/swagger-ui/issues/374) type should be `file`. – Egemen Apr 29 '16 at 07:27