8

I have my spec which have a path with a 200 response code, that response code can access multiple content-types, I want to add the Content-Disposition Header to one of those content-types.

Here's a sample:

openapi: '3.0.3'
info:
...
servers:
  ...
paths:          
  /examples:
    ...
    get:
      ...
      responses:
        '200':
          content:
            application/json:
              ...
            application/pdf:
              encoding:
                file:
                  headers:
                    Content-Disposition:
                      schema:
                        type: string
                        example: attachment; filename="name.pdf"
              examples:
                file:
                  summary: File
                  externalValue: https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf

Here's the generated view:

no header

Here is an example where the header is added (for another endpoint)

responses:
  '201':
    description: Success
    headers:
      Location:
        schema:
          type: string
          format: uri
        description: The URI to the newly created example

And here's the generated view for that one:

with header

Am I doing something wrong?

1 Answers1

6

encoding.<name>.headers is used to define headers for individual parts of a multipart/* request body, which is different from your scenario. Since your response is not multipart/*, the response headers must be defined in responses.<code>.headers.

However, OpenAPI does not have a way to vary response headers per media type. What you can do is define the Content-Disposition response header as optional and explain that it only applies to applicatioln/pdf responses.

paths:          
  /examples:
    get:
      responses:
        '200':
          description: ok
          content:
            application/pdf:
              schema:
                type: string
                format: binary
          headers:
            Content-Disposition:
              schema:
                type: string
              description: Used only with `application/pdf` responses.
              example: attachment; filename="name.pdf"
tom redfern
  • 30,562
  • 14
  • 91
  • 126
Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thanks for the answer, it's a shame we can't do that, but I'll try the approach you mentioned – Armando González Jul 05 '20 at 20:09
  • @ArmandoGonzález you can submit an enhancement request in the OpenAPI Specification repository: https://github.com/OAI/OpenAPI-Specification/issues – Helen Jul 05 '20 at 20:37