Skip to content

Commit d17c44d

Browse files
authored
Merge pull request #4903 from handrews/set-cookie-example
2 parents e4c0230 + 585321d commit d17c44d

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

src/oas.md

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

30933093
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.
30943094

3095-
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:
3095+
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.
3096+
3097+
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:
30963098

30973099
```yaml
30983100
components:
30993101
headers:
3100-
SetCookieWithExpires:
3101-
# Spaces within the Expires values prevent the use of `schema` and
3102-
# `style` as they would be percent-encoded, even with `allowReserved`.
3102+
SetCookieWithContent:
31033103
content:
31043104
text/plain:
31053105
schema:
@@ -3111,46 +3111,55 @@ components:
31113111
# This demonstrates that the text is required to be provided
31123112
# in the final format, and is not changed by serialization.
31133113
# In practice, it is not necessary to show both value fields.
3114+
# Note that only the comma (%2C) would need to be percent-encoded
3115+
# if percent-encoding were only being done to make the value
3116+
# a valid cookie, as space (%20) and the exclamation point (%21)
3117+
# are allowed in cookies, but not in URLs. See the cookie
3118+
# input parameter examples for an example of encoding only
3119+
# what is needed for the cookie syntax.
31143120
dataValue: |
31153121
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
31163122
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3123+
urlSafeData: Hello%2C%20world%21
31173124
serializedValue: |
31183125
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
31193126
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3120-
SetCookieWithNoSpaces:
3127+
urlSafeData: Hello%2C%20world%21
3128+
SetCookieWithSchemaAndStyle:
31213129
schema:
31223130
type: object
31233131
required:
31243132
- lang
31253133
- foo
3134+
- urlSafeData
3135+
properties:
3136+
urlSafeData:
3137+
type: string
3138+
pattern: ^[-_.%a-zA-Z0-9]+(;|$)
31263139
additionalProperties:
3127-
type: string
3128-
pattern: "^[^[:space:]]*$"
3140+
$comment: Require an Expires parameter
3141+
pattern: "; *Expires="
31293142
style: simple
31303143
explode: true
31313144
examples:
31323145
SetCookies:
31333146
dataValue: {
3134-
"lang": "en-US",
3135-
"foo": "bar"
3147+
"lang": "en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
3148+
"foo": "bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT"
3149+
"urlSafeData": "Hello%2C%20world%21"
31363150
}
31373151
serializedValue: |
3138-
lang=en-US
3139-
foo=bar
3152+
lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3153+
foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3154+
urlSafeData: Hello%2C%20world%21
31403155
```
31413156
3142-
In an HTTP message, the serialized example with Expires would look like:
3157+
In an HTTP message, the serialized example would look like:
31433158
31443159
```http
31453160
Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GM
31463161
Set-Cookie: foo=bar; Expires=Wed, 09 Jun 2021 10:18:14 GMT
3147-
```
3148-
3149-
and the example without Expires would look like:
3150-
3151-
```http
3152-
Set-Cookie: lang=en-US
3153-
Set-Cookie: foo=bar
3162+
Set-Cookie: urlSafeData=Hello%2C%20world%21
31543163
```
31553164
31563165
##### Header Object Example

0 commit comments

Comments
 (0)