Openapi-specification: Share header with multiple response objects

Created on 19 May 2015  路  9Comments  路  Source: OAI/OpenAPI-Specification

Can there not just be a simple header generically at the response level not specific to each of the status codes? For our case, this kind of header is 99% the same across our codebase.

---

responses:
  200:
    description: no error
    headers:
      Content-Type:
        description: application/json
        type: string

It would be a pain to copy+paste this to each and every routine that supports HTTP JSON responses.

OpenAPI.Next Proposal

Most helpful comment

Obviously the example is bad. consider the following model:

paths:
  /api/v1/modules:
    get:
      tags:
        - Modules
      summary: Lists all available modules
      operationId: listModules
      responses:
        200:
          $ref: "#/components/responses/modulesOk"
        400:
          $ref: "#/components/responses/400"
        401:
          $ref: "#/components/responses/401"
        403:
          $ref: "#/components/responses/403"
        404:
          $ref: "#/components/responses/404"
        406:
          $ref: "#/components/responses/406"
        408:
          $ref: "#/components/responses/408"
        500:
          $ref: "#/components/responses/500"

Codes like 401, 403, 404, 406, 408 will repeat through all paths. If one could add this to a generic section and selectively overwrite it, it'd be great. Having 50 paths and adding that block over and over again ist just pain.

All 9 comments

Unfortunately, no. The headers in the responses is actually a new feature in 2.0, and we hadn't thought of the option to allow a global definition for it.

@webron Given your response above, should we close this issue? /cc @huangsam

It's still an option we might consider in future versions.

Isn't this handled in 3.0 You define your reusable headers at #/components/headers and then use a $ref to reuse it. It won't allow you to have a singular reference to define all common headers in a response but then you could probably use #/components/responses for that.

Yeah, but this is not about reusability (which makes it easier) - it's about declaring it only once for all.

What happens when someone declares a Content-Type header for all responses and then adds a 204 response?

@darrelmiller did we not just talk today about disallowing Content-Type headers? :)

@webron Fine: content-length, Transfer-encoding, Range, ... how obscure do I need to get? :-)

Obviously the example is bad. consider the following model:

paths:
  /api/v1/modules:
    get:
      tags:
        - Modules
      summary: Lists all available modules
      operationId: listModules
      responses:
        200:
          $ref: "#/components/responses/modulesOk"
        400:
          $ref: "#/components/responses/400"
        401:
          $ref: "#/components/responses/401"
        403:
          $ref: "#/components/responses/403"
        404:
          $ref: "#/components/responses/404"
        406:
          $ref: "#/components/responses/406"
        408:
          $ref: "#/components/responses/408"
        500:
          $ref: "#/components/responses/500"

Codes like 401, 403, 404, 406, 408 will repeat through all paths. If one could add this to a generic section and selectively overwrite it, it'd be great. Having 50 paths and adding that block over and over again ist just pain.

Was this page helpful?
0 / 5 - 0 ratings