OpenAPI Header Parameters
Header parameters are serialized at runtime to the HTTP headers of the request. Types are generally serialized to a string representation, and only simple style is available.
Explode defaults to false.
There are a few reserved headers that cannot be used as parameter names and are enabled by other OpenAPI features:
Accept- Defining content types in the Response Objectcontentfield, documents the available values for theAcceptheader.Authorization- Defining security requirements in the Security Requirement Objectsecurityfield, documents that theAuthorizationheader is required.Content-Type- Defining content types in the Request Body Objectcontentfield, documents that theContent-Typeheader is required and the acceptable values.
If using headers for authentication, it is recommended to use the OpenAPI security field to document a security scheme instead of a header parameter.
Primitive Types As Headers in OpenAPI
Primitive types such as string, number, integer, and boolean are serialized as a string.
For the example below, we will use a header parameter named X-Drink-Limit with a value of 5.
Primitive Types Serialization
Simple Arrays As Headers in OpenAPI
For simple arrays of primitive types such as string, number, integer, and boolean, the style and explode fields have little effect on the serialization.
For the example below, we will use a header parameter named X-Drink-Types with a value of ["gin", "vodka", "rum"].
Simple Arrays Serialization
Simple Objects As Headers in OpenAPI
For simple objects whose fields are primitive types such as string, number, integer, and boolean, serialization will vary depending on the explode field.
For the example below, we will use a header parameter named X-Drink-Filter with a value of {"type": "cocktail", "strength": 5}.
Simple Objects Serialization
Complex Objects and Arrays As Headers in OpenAPI
For complex objects and arrays, serialization in a header parameter is only really possible using content and not any style options.
For example, to serialize using JSON, the following:
Would serialize to X-Drink-Filter: {"type":["cocktail","mocktail"],"strength":[5,10]}.
Last updated on