Skip to content

Commit 75ac257

Browse files
authored
Merge pull request #4801 from handrews/param-header-ex-3
v3.2: Parameter and Header example updates
2 parents 774f70c + 5620635 commit 75ac257

File tree

1 file changed

+111
-13
lines changed

1 file changed

+111
-13
lines changed

src/oas.md

Lines changed: 111 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ Two avenues are available for supporting such formats with `in: "querystring"`:
12541254
A header parameter with an array of 64-bit integer numbers:
12551255

12561256
```yaml
1257-
name: token
1257+
name: X-Token
12581258
in: header
12591259
description: token to be passed as a header
12601260
required: true
@@ -1264,6 +1264,10 @@ schema:
12641264
type: integer
12651265
format: int64
12661266
style: simple
1267+
examples:
1268+
Tokens:
1269+
dataValue: [12345678, 90099]
1270+
serializedValue: "12345678,90099"
12671271
```
12681272

12691273
A path parameter of a string value:
@@ -1275,24 +1279,39 @@ description: username to fetch
12751279
required: true
12761280
schema:
12771281
type: string
1282+
examples:
1283+
"Edsger Dijkstra":
1284+
dataValue: edijkstra
1285+
serializedValue: edijkstra
1286+
Diṅnāga:
1287+
dataValue: diṅnāga
1288+
serializedValue: di%E1%B9%85n%C4%81ga
1289+
examples:
1290+
Al-Khwarizmi:
1291+
dataValue: "الخوارزميّ"
1292+
serializedValue: "%D8%A7%D9%84%D8%AE%D9%88%D8%A7%D8%B1%D8%B2%D9%85%D9%8A%D9%91"
12781293
```
12791294

1280-
An optional query parameter of a string value, allowing multiple values by repeating the query parameter:
1295+
An optional query parameter of a string value, allowing multiple values by repeating the query parameter
1296+
(Note that we use `"%20"` in place of `" "` (space) because that is how RFC6570 handles it; for guidance on using `+` to represent the space character, see [Appendix E](#appendix-e-percent-encoding-and-form-media-types) for more guidance on these escaping options):
12811297

12821298
```yaml
1283-
name: id
1299+
name: thing
12841300
in: query
1285-
description: ID of the object to fetch
12861301
required: false
12871302
schema:
12881303
type: array
12891304
items:
12901305
type: string
12911306
style: form
12921307
explode: true
1308+
examples:
1309+
ObjectList:
1310+
dataValue: ["one thing", "another thing"]
1311+
serializedValue: "thing=one%20thing&thing=another%20thing"
12931312
```
12941313

1295-
A free-form query parameter, allowing undefined parameters of a specific type:
1314+
A free-form query parameter, allowing arbitrary parameters of `type: "integer"`:
12961315
12971316
```yaml
12981317
in: query
@@ -1302,9 +1321,16 @@ schema:
13021321
additionalProperties:
13031322
type: integer
13041323
style: form
1324+
examples:
1325+
Pagination:
1326+
dataValue: {
1327+
"page": 4,
1328+
"pageSize": 50
1329+
}
1330+
serializeValue: page=4&pageSize=50
13051331
```
13061332
1307-
A complex parameter using `content` to define serialization:
1333+
A complex parameter using `content` to define serialization, with multiple levels and types of examples shown to make the example usage options clear — note that `dataValue` is the same at both levels and does not need to be shown in both places in normal usage, but `serializedValue` is different:
13081334

13091335
```yaml
13101336
in: query
@@ -1321,32 +1347,96 @@ content:
13211347
type: number
13221348
long:
13231349
type: number
1350+
examples:
1351+
dataValue: {
1352+
"lat": 10,
1353+
"long": 60
1354+
}
1355+
serializedValue: '{"lat":10,"long":60}'
1356+
examples:
1357+
dataValue: {
1358+
"lat": 10,
1359+
"long": 60
1360+
}
1361+
serializedValue: coordinates=%7B%22lat%22%3A10%2C%22long%22%3A60%7D
1362+
```
1363+
1364+
A querystring parameter using regular form encoding, but managed with a Media Type Object.
1365+
This shows spaces being handled per the `application/x-www-form-urlencoded` media type rules (encode as `+`) rather than the RFC6570 process (encode as `%20`); see [Appendix E](appendix-e-percent-encoding-and-form-media-types) for further guidance on this distinction.
1366+
Examples are shown at both the media type and parameter level to emphasize that, since `application/x-www-form-urlencoded` is suitable for use in query strings by definition, no further encoding or escaping is applied to the serialized media type value:
1367+
1368+
```yaml
1369+
in: querystring
1370+
content:
1371+
application/x-www-form-urlencoded:
1372+
schema:
1373+
type: object
1374+
properties:
1375+
foo:
1376+
type: string
1377+
bar:
1378+
type: boolean
1379+
examples:
1380+
spacesAndPluses:
1381+
description: Note handling of spaces and "+" per media type.
1382+
dataValue:
1383+
foo: a + b
1384+
bar: true
1385+
serializedValue: foo=a+%2B+b&bar=true
1386+
examples:
1387+
spacesAndPluses:
1388+
description: |
1389+
Note that no additional percent encoding is done, as this
1390+
media type is URI query string-ready by definition.
1391+
dataValue:
1392+
foo: a + b
1393+
bar: true
1394+
serializedValue: foo=a+%2B+b&bar=true
13241395
```
13251396

1326-
A querystring parameter that uses JSON for the entire string (not as a single query parameter value):
1397+
A querystring parameter that uses JSON for the entire string (not as a single query parameter value).
1398+
The `dataValue` field is shown at both levels to fully illustrate both ways of providing an example.
1399+
As seen below, this is redundant and need not be done in practice:
13271400

13281401
```yaml
13291402
in: querystring
13301403
name: json
13311404
content:
13321405
application/json:
13331406
schema:
1334-
# Allow an arbitrary JSON object to keep
1335-
# the example simple
13361407
type: object
1337-
example: {
1408+
properties:
1409+
numbers:
1410+
type: array
1411+
items:
1412+
type: integer
1413+
flag:
1414+
type: [boolean, "null"]
1415+
examples:
1416+
TwoNoFlag:
1417+
description: Serialize with minimized whitespace
1418+
dataValue: {
1419+
"numbers": [1, 2],
1420+
"flag": null
1421+
}
1422+
serializedValue: '{"numbers":[1,2],"flag":null}'
1423+
examples:
1424+
TwoNoFlag:
1425+
dataValue: {
13381426
"numbers": [1, 2],
13391427
"flag": null
13401428
}
1429+
serializedValue: "%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D"
13411430
```
13421431

1343-
Assuming a path of `/foo`, a server of `https://example.com`, the full URL incorporating the value from the `example` field (with whitespace minimized) would be:
1432+
Assuming a path of `/foo`, a server of `https://example.com`, the full URL incorporating the value from `serializedValue` would be:
13441433

13451434
```uri
13461435
https://example.com/foo?%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D
13471436
```
13481437

1349-
A querystring parameter that uses JSONPath:
1438+
A querystring parameter that uses JSONPath.
1439+
Note that in this example we not only do not repeat `dataValue`, but we use the shorthand `example` because the `application/jsonpath` value is a string that, at the media type level, is serialized as-is:
13501440

13511441
```yaml
13521442
in: querystring
@@ -1356,11 +1446,14 @@ content:
13561446
schema:
13571447
type: string
13581448
example: $.a.b[1:1]
1449+
examples:
1450+
Selector:
1451+
serializedValue: "%24.a.b%5B1%3A1%5D"
13591452
```
13601453

13611454
As there is not, as of this writing, a [registered](#media-type-registry) mapping between the JSON Schema data model and JSONPath, the details of the string's allowed structure would need to be conveyed either in a human-readable `description` field, or through a mechanism outside of the OpenAPI Description, such as a JSON Schema for the data structure to be queried.
13621455

1363-
Assuming a path of `/foo` and a server of `https://example.com`, the full URL incorporating the value from the `example` field would be:
1456+
Assuming a path of `/foo` and a server of `https://example.com`, the full URL incorporating the value from `serializedValue` would be:
13641457

13651458
```uri
13661459
https://example.com/foo?%24.a.b%5B1%3A1%5D
@@ -2881,7 +2974,12 @@ ETag:
28812974
text/plain:
28822975
schema:
28832976
type: string
2977+
# Note that quotation markes are part of the
2978+
# ETag value, unlike many other headers that
2979+
# use a quoted string purely for managing
2980+
# reserved characters.
28842981
pattern: ^"
2982+
example: '"xyzzy"'
28852983
```
28862984

28872985
#### Tag Object

0 commit comments

Comments
 (0)