Skip to content

Commit 44eda57

Browse files
authored
Merge pull request #3867 from handrews/header-obj-304
Verbose Header Object documentation (3.0.4)
2 parents d3e0238 + bace4b4 commit 44eda57

File tree

1 file changed

+75
-6
lines changed

1 file changed

+75
-6
lines changed

Diff for: versions/3.0.4.md

+75-6
Original file line numberDiff line numberDiff line change
@@ -2336,18 +2336,56 @@ Expressions can be embedded into string values by surrounding the expression wit
23362336

23372337
#### <a name="headerObject"></a>Header Object
23382338

2339-
The Header Object follows the structure of the [Parameter Object](#parameterObject) with the following changes:
2339+
Describes a single header for [HTTP responses](#responseHeaders) and for [individual parts in `multipart` representations](#encodingHeaders); see the relevant [Response Object](#responseObject) and [Encoding Object](#encodingObject) documentation for restrictions on which headers can be described.
2340+
2341+
The Header Object follows the structure of the [Parameter Object](#parameterObject), including determining its serialization strategy based on whether `schema` or `content` is present, with the following changes:
23402342

23412343
1. `name` MUST NOT be specified, it is given in the corresponding `headers` map.
23422344
1. `in` MUST NOT be specified, it is implicitly in `header`.
2343-
1. All traits that are affected by the location MUST be applicable to a location of `header` (for example, [`style`](#parameterStyle)).
2345+
1. All traits that are affected by the location MUST be applicable to a location of `header` (for example, [`style`](#parameterStyle)). This means that `allowEmptyValue` and `allowReserved` MUST NOT be used, and `style`, if used, MUST be limited to `simple`.
2346+
2347+
###### Common Fixed Fields
2348+
2349+
These fields MAY be used with either `content` or `schema`.
2350+
2351+
Field Name | Type | Description
2352+
---|:---:|---
2353+
<a name="headerDescription"></a>description | `string` | A brief description of the header. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation.
2354+
<a name="headerRequired"></a>required | `boolean` | Determines whether this header is mandatory. The default value is `false`.
2355+
<a name="headerDeprecated"></a> deprecated | `boolean` | Specifies that the header is deprecated and SHOULD be transitioned out of usage. Default value is `false`.
2356+
2357+
###### Fixed Fields for use with `schema`
2358+
2359+
For simpler scenarios, a [`schema`](#headerSchema) and [`style`](#headerStyle) can describe the structure and syntax of the header.
2360+
When `example` or `examples` are provided in conjunction with the `schema` object, the example MUST follow the prescribed serialization strategy for the header.
2361+
2362+
Serializing with `schema` is NOT RECOMMENDED for headers with parameters (name=value pairs following a `;`) in their values, or where values might have non-URL-safe characters; see [Appendix D](#serializingHeadersAndCookies) for details.
2363+
2364+
Field Name | Type | Description
2365+
---|:---:|---
2366+
<a name="headerStyle"></a>style | `string` | Describes how the header value will be serialized. The default (and only legal value for headers) is `simple`.
2367+
<a name="headerExplode"></a>explode | `boolean` | When this is true, header values of type `array` or `object` generate a single header whose value is a comma-separated list of the array items or key-value pairs of the map, see [Style Examples](#style-examples). For other data types this property has no effect. The default value is `false`.
2368+
<a name="headerSchema"></a>schema | [Schema Object](#schemaObject) \| [Reference Object](#referenceObject) | The schema defining the type used for the header.
2369+
<a name="headerExample"></a>example | Any | Example of the header's potential value. The example SHOULD match the specified schema and encoding properties if present. The `example` field is mutually exclusive of the `examples` field. Furthermore, if referencing a `schema` that contains an example, the `example` value SHALL _override_ the example provided by the schema. To represent examples of media types that cannot naturally be represented in JSON or YAML, a string value can contain the example with escaping where necessary.
2370+
<a name="headerExamples"></a>examples | Map[ `string`, [Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the header's potential value. Each example SHOULD contain a value in the correct format as specified in the header encoding. The `examples` field is mutually exclusive of the `example` field. Furthermore, if referencing a `schema` that contains an example, the `examples` value SHALL _override_ the example provided by the schema.
2371+
2372+
See also [Appendix C: Using RFC6570 Implementations](#usingRFC6570Implementations) for additional guidance.
2373+
2374+
###### Fixed Fields for use with `content`
2375+
2376+
For more complex scenarios, the [`content`](#headerContent) property can define the media type and schema of the header, as well as give examples of its use.
2377+
Using `content` with a `text/plain` media type is RECOMMENDED for headers where the `schema` strategy is not appropriate.
2378+
2379+
Field Name | Type | Description
2380+
---|:---:|---
2381+
<a name="headerContent"></a>content | Map[`string`, [Media Type Object](#mediaTypeObject)] | A map containing the representations for the header. The key is the media type and the value describes it. The map MUST only contain one entry.
23442382

23452383
##### Header Object Example
23462384

23472385
A simple header of type `integer`:
23482386

23492387
```json
2350-
{
2388+
"X-Rate-Limit-Limit": {
23512389
"description": "The number of allowed requests in the current period",
23522390
"schema": {
23532391
"type": "integer"
@@ -2356,9 +2394,36 @@ A simple header of type `integer`:
23562394
```
23572395

23582396
```yaml
2359-
description: The number of allowed requests in the current period
2360-
schema:
2361-
type: integer
2397+
X-Rate-Limit-Limit:
2398+
description: The number of allowed requests in the current period
2399+
schema:
2400+
type: integer
2401+
```
2402+
2403+
Requiring that a strong `ETag` header (with a value starting with `"` rather than `W/`) is present. Note the use of `content`, because using `schema` and `style` would require the `"` to be percent-encoded as `%22`:
2404+
2405+
```json
2406+
"ETag": {
2407+
"required": true,
2408+
"content": {
2409+
"text/plain": {
2410+
"schema": {
2411+
"type": "string",
2412+
"pattern": "^\""
2413+
}
2414+
}
2415+
}
2416+
}
2417+
```
2418+
2419+
```yaml
2420+
ETag:
2421+
required: true
2422+
content:
2423+
text/plain:
2424+
schema:
2425+
type: string
2426+
pattern: ^"
23622427
```
23632428

23642429
#### <a name="tagObject"></a>Tag Object
@@ -3631,3 +3696,7 @@ Version | Date | Notes
36313696
1.2 | 2014-03-14 | Initial release of the formal document.
36323697
1.1 | 2012-08-22 | Release of Swagger 1.1
36333698
1.0 | 2011-08-10 | First release of the Swagger Specification
3699+
3700+
## <a name="usingRFC6570Implementations"></a>Appendix C: Using RFC6570 Implementations
3701+
3702+
## <a name="serializingHeadersAndCookies"></a>Appendix D: Serializing Headers and Cookies

0 commit comments

Comments
 (0)