You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warnings for header and cookie serialization (3.0.4)
This makes serializing cookie paramters and most header parameters
with `schema` and `style` NOT RECOMMENDED.
It is not clear that any `schema`-based serialization for cookies
will produce a correct value (although the reason is sufficiently
obscure that many implementations might ignore it and produce
cookie-compliant output anyway).
With headers, there are numerous pitfalls and only the simplest
scenarios will work properly, although perhaps the warning
here could be reworded to emphasize the safe scenarios more clearly.
The details are relegated to an appendix, because truly, most
people will not want to know. But recommending against syntactically
legal configurations really does need to be explained in the spec.
Also, don't use
- in: header
name: Cookie
Because... yeah.
Copy file name to clipboardExpand all lines: versions/3.0.4.md
+28-2
Original file line number
Diff line number
Diff line change
@@ -1037,7 +1037,6 @@ There are four possible parameter locations specified by the `in` field:
1037
1037
* header - Custom headers that are expected as part of the request. Note that [RFC7230](https://tools.ietf.org/html/rfc7230#page-22) states header names are case insensitive.
1038
1038
* cookie - Used to pass a specific cookie value to the API.
1039
1039
1040
-
1041
1040
##### Fixed Fields
1042
1041
1043
1042
The rules for serialization of the parameter are specified in one of two ways.
@@ -1056,11 +1055,15 @@ Field Name | Type | Description
1056
1055
<a name="parameterDeprecated"></a> deprecated | `boolean` | Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is `false`.
1057
1056
<a name="parameterAllowEmptyValue"></a> allowEmptyValue | `boolean` | If `true`, clients MAY pass a zero-length string value in place of parameters that would otherwise be omitted entirely, which the server SHOULD interpret as the parameter being unused. Default value is `false`. If [`style`](#parameterStyle) is used, and if behavior is `n/a` (cannot be serialized), the value of `allowEmptyValue` SHALL be ignored. Interactions between this field and the parameter's [Schema Object](#schemaObject) are implementation-defined. This field is valid only for `query` parameters. Use of this property is NOT RECOMMENDED, and it is likely to be removed in a later revision.
1058
1057
1058
+
Note that while `"Cookie"` as a `name` is not forbidden with `in: header`, the effect of defining a cookie parameter that way is undefined; use `in: cookie` instead.
1059
+
1059
1060
###### Fixed Fields for use with `schema`
1060
1061
1061
1062
For simpler scenarios, a [`schema`](#parameterSchema) and [`style`](#parameterStyle) can describe the structure and syntax of the parameter.
1062
1063
When `example` or `examples` are provided in conjunction with the `schema` object, the example MUST follow the prescribed serialization strategy for the parameter.
1063
1064
1065
+
Serializing with `schema` is NOT RECOMMENDED for `in: cookie` parameters, `in: header` paramters that use HTTP header parameters (name=value pairs following a `;`) in their values, or `in: header` parameters where values might have non-URL-safe characters; see [Appendix D](#serializingHeadersAndCookies) for details.
1066
+
1064
1067
Field Name | Type | Description
1065
1068
---|:---:|---
1066
1069
<a name="parameterStyle"></a>style | `string` | Describes how the parameter value will be serialized depending on the type of the parameter value. Default values (based on value of `in`): for `query` - `form`; for `path` - `simple`; for `header` - `simple`; for `cookie` - `form`.
@@ -1070,14 +1073,16 @@ Field Name | Type | Description
1070
1073
<a name="parameterExample"></a>example | Any | Example of the parameter'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.
1071
1074
<a name="parameterExamples"></a>examples | Map[ `string`, [Example Object](#exampleObject) \| [Reference Object](#referenceObject)] | Examples of the parameter's potential value. Each example SHOULD contain a value in the correct format as specified in the parameter 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.
1072
1075
1073
-
###### Fixed Fields and considerations for use with `content`
1076
+
###### Fixed Fields for use with `content`
1074
1077
1075
1078
For more complex scenarios, the [`content`](#parameterContent) property can define the media type and schema of the parameter, as well as give examples of its use.
1079
+
Using `content` with a `text/plain` media type is RECOMMENDED for `in: header` and `in: cookie` parameters where the `schema` strategy is not appropriate.
1076
1080
1077
1081
Field Name | Type | Description
1078
1082
---|:---:|---
1079
1083
<a name="parameterContent"></a>content | Map[`string`, [Media Type Object](#mediaTypeObject)] | A map containing the representations for the parameter. The key is the media type and the value describes it. The map MUST only contain one entry.
1080
1084
1085
+
1081
1086
##### Style Values
1082
1087
1083
1088
In order to support common ways of serializing simple parameters, a set of `style` values are defined.
@@ -3505,3 +3510,24 @@ Version | Date | Notes
3505
3510
1.2 | 2014-03-14 | Initial release of the formal document.
3506
3511
1.1 | 2012-08-22 | Release of Swagger 1.1
3507
3512
1.0 | 2011-08-10 | First release of the Swagger Specification
3513
+
3514
+
## <a name="serializingHeadersAndCookies"></a>Appendix D: Serializing Headers and Cookies
3515
+
3516
+
RFC6570's percent-encoding behavior is not always appropriate for `in: header` and `in: cookie` parameters.
3517
+
In many cases, it is more appropriate to use `content` with a media type such as `text/plain` and require the application to assemble the correct string.
3518
+
3519
+
For both cookies ([RFC6265](https://www.rfc-editor.org/rfc/rfc6265)) and HTTP headers using the structured fields ([RFC8941](https://www.rfc-editor.org/rfc/rfc8941)) syntax, non-ASCII content is handled using base64 encoding (`format: byte`).
3520
+
Note that the standard base64 encoding alphabet includes non-URL-safe characters that are percent-encoded by RFC6570 expansion; serializing values through both encodings is NOT RECOMMENDED.
3521
+
3522
+
Most HTTP headers predate the structured field syntax, and a comprehensive assessment of their syntax and encoding rules is well beyond the scope of this specification.
3523
+
While [RFC8187](https://www.rfc-editor.org/rfc/rfc8187) recommends percent-encoding HTTP field (header or trailer) parameters, these parameters appear after a `;` character.
3524
+
With `style: simple`, that delimiter would itself be percent-encoded, violating the general HTTP field syntax.
3525
+
3526
+
Using `style: form` with `in: cookie` is ambiguous for a single value, and incorrect for multiple values.
3527
+
This is true whether the multiple values are the result of using `explode: true` or not.
3528
+
3529
+
This style is specified to be equivalent to RFC6570 form expansion which includes the `?` character (see Appendix C for more details), which is not part of the cookie syntax.
3530
+
However, examples of this style in past versions of this specification have not included the `?` prefix, suggesting that the comparison is not exact.
3531
+
Because implementations that rely on an RFC6570 implementation and those that perform custom serialization based on the style example will produce different results, it is implementation-defined as to which of the two results is correct.
3532
+
3533
+
For multiple values, `style: form` is always incorrect as name=value pairs in cookies are delimited by `; ` (a semicolon followed by a space character) rather than `&`.
0 commit comments