Skip to content

Commit 0e8e7e3

Browse files
committed
Update Set-Cookie example for recent changes
Changes to our understanding of percent-encoding and headers have made the previous example incorrect. This brings it into agreement with the new recommendations. This also explains how percent-encoding and other escaping is handled, and links to the updated Appendix D which provids more detail including a link to the IETF draft update of the cookie RFC that clarifies this.
1 parent 0193c67 commit 0e8e7e3

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

src/oas.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,14 +3036,14 @@ For HTTP messages, this is purely a serialization concern, and no more of a prob
30363036

30373037
However, because examples and values modeled with `content` do not incorporate the header name, for these fields `Set-Cookie` MUST be handled by placing each value on a separate line, without the header name or the `:` delimiter.
30383038

3039-
The following example shows two different ways to describe `Set-Cookie` headers that require cookies named `"lang"` and `"foo"`. The first uses `content` to preserve the necessary whitespace in the `"Expires"` cookie attribute, while the second shows the use of `style: "simple"` and forbids whitespace to ensure that values work with this serialization approach:
3039+
Note also that any URI percent-encoding, base64 encoding, or other escaping MUST be performed prior to supplying the data to OAS tooling; see [Appendix D](appendix-d-serializing-headers-and-cookies) for details.
3040+
3041+
The following example shows two different ways to describe `Set-Cookie` headers that require cookies named `"lang"` and `"foo"`, as well as a `"urlSafeData"` cookie that is expected to be percent-encoded. The first uses `content` in order to show exactly how such examples are formatted, but also notes the limitations of schema constraints with multi-line text. The second shows the use of `style: "simple"`, which produces the same serialized example text (with each line corresponding to one `Set-Cookie:` line in the HTTP response), but allows schema constraints on each cookie; note that the percent-encoding is already applied in the `dataValue` field of the example:
30403042

30413043
```yaml
30423044
components:
30433045
headers:
3044-
SetCookieWithExpires:
3045-
# Spaces within the Expires values prevent the use of `schema` and
3046-
# `style` as they would be percent-encoded, even with `allowReserved`.
3046+
SetCookieWithContent:
30473047
content:
30483048
text/plain:
30493049
schema:
@@ -3058,45 +3058,47 @@ components:
30583058
dataValue: |
30593059
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
30603060
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3061+
urlSafeData: Hello%2C%20world%21
30613062
serializedValue: |
30623063
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
30633064
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3064-
SetCookieWithNoSpaces:
3065+
urlSafeData: Hello%2C%20world%21
3066+
SetCookieWithSchemaAnd Style:
30653067
schema:
30663068
type: object
30673069
required:
30683070
- lang
30693071
- foo
3072+
- urlSafeData
3073+
properties:
3074+
urlSafeData:
3075+
type: string
3076+
pattern: ^[-_.%a-zA-Z0-9]+(;|$)
30703077
additionalProperties:
3071-
type: string
3072-
pattern: "^[^[:space:]]*$"
3078+
# Require an Expires parameter
3079+
pattern: "; *Expires="
30733080
style: simple
30743081
explode: true
30753082
examples:
30763083
SetCookies:
30773084
dataValue: {
3078-
"lang": "en-US",
3079-
"foo": "bar"
3085+
"lang": "en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
3086+
"foo": "bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
3087+
"urlSafeData": "Hello%2C%20world%21"
30803088
}
30813089
serializedValue: |
3082-
lang=en-US
3083-
foo=bar
3090+
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3091+
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3092+
urlSafeData: Hello%2C%20world%21
30843093
```
30853094
3086-
In an HTTP message, the serialized example with Expires would look like:
3095+
In an HTTP message, the serialized example would look like:
30873096
30883097
```http
30893098
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GM
30903099
Set-Cookie: foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
30913100
```
30923101
3093-
and the example without Expires would look like:
3094-
3095-
```http
3096-
Set-Cookie: lang=en-US
3097-
Set-Cookie: foo=bar
3098-
```
3099-
31003102
##### Header Object Example
31013103
31023104
A simple header of type `integer`:

0 commit comments

Comments
 (0)