Openapi-specification: Clarify if header is required to be sent in the response

Created on 5 Apr 2015  路  12Comments  路  Source: OAI/OpenAPI-Specification

Given the headers section has a definition for a given header (let's say ETag) the question is:

Is the header required to be present in the response sent by the server?

headers: A list of headers that are sent with the response.
https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#fixed-fields-10

Headers object: Lists the headers that can be sent as part of a response.
https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#headersObject

Reading the first definition I understand that is _REQUIRED_.
Reading the second definition I understand that is _OPTIONAL_.

Spec should be rephrased clarifying this aspect.

OpenAPI.Next Proposal Sub Issue

Most helpful comment

Totally agree with @nfroidure proposal (add a required property in header object).
We already have that for parameters (headers and non body parameters objects have a lot in common) , why couldn't we have the same thing on returned headers?

All 12 comments

IMO should be addressed as _REQUIRED_

That's an interesting and fair question. I'll have to dig into the discussions about it to see if we mentioned anything specific about it. However, even the first definition doesn't necessarily mean it is required, but rather suggested. Normally, when something is required, the term MUST is normally used across the spec to mention something is REQUIRED. However, I agree it is not clear enough and should be revised.

The argument which I think MUST be REQUIRED is that the header is linked to the response HTTP Code.

So it's specific enough to assume these headers will be received always for this HTTP Code.

I'm not disagreeing, but if the intent wasn't clarified originally, I may not be able to clarify it in this version of the spec as well. The current wording implies OPTIONAL over REQUIRED, but as said, I'll look into it.

What about a required=true attribute in the headers object definition?
https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#headersObject

I think it strongly depends on each headers type.

I only suggest when possible use the same validation rules as JSON-Schema. required: boolean is not a valid attribute.

Wasn't aware of the JSON-Schema compliance, but any property indicating the requirement would be great as well.

minLength and the rest of those validators are related with the value. i.e if the header value has a minLengh of 1.

Totally agree with @nfroidure proposal (add a required property in header object).
We already have that for parameters (headers and non body parameters objects have a lot in common) , why couldn't we have the same thing on returned headers?

Parent: #560

The Header Object now follows a similar pattern to the Parameter Object and contains a required field which is by default false.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slinkydeveloper picture slinkydeveloper  路  4Comments

john1452 picture john1452  路  5Comments

niquola picture niquola  路  5Comments

andy-maier picture andy-maier  路  4Comments

muhmud picture muhmud  路  5Comments