Skip to content

Commit 62751e7

Browse files
committed
Parameter and Header example updates
This updates for both the new example fields and for examples with `content`
1 parent 2c7432c commit 62751e7

File tree

1 file changed

+107
-13
lines changed

1 file changed

+107
-13
lines changed

src/oas.md

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

10831083
```yaml
1084-
name: token
1084+
name: X-Token
10851085
in: header
10861086
description: token to be passed as a header
10871087
required: true
@@ -1091,6 +1091,10 @@ schema:
10911091
type: integer
10921092
format: int64
10931093
style: simple
1094+
examples:
1095+
Tokens:
1096+
dataValue: [12345678, 90099]
1097+
serializedValue: "12345678,90099"
10941098
```
10951099

10961100
A path parameter of a string value:
@@ -1102,24 +1106,39 @@ description: username to fetch
11021106
required: true
11031107
schema:
11041108
type: string
1109+
examples:
1110+
"Edsger Dijkstra":
1111+
dataValue: edijkstra
1112+
serializedValue: edijkstra
1113+
Diṅnāga:
1114+
dataValue: diṅnāga
1115+
serializedValue: di%E1%B9%85n%C4%81ga
1116+
examples:
1117+
Al-Khwarizmi:
1118+
dataValue: "الخوارزميّ"
1119+
serializedValue: "%D8%A7%D9%84%D8%AE%D9%88%D8%A7%D8%B1%D8%B2%D9%85%D9%8A%D9%91"
11051120
```
11061121

1107-
An optional query parameter of a string value, allowing multiple values by repeating the query parameter:
1122+
An optional query parameter of a integer value, allowing multiple values by repeating the query parameter
1123+
(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):
11081124

11091125
```yaml
1110-
name: id
1126+
name: thing
11111127
in: query
1112-
description: ID of the object to fetch
11131128
required: false
11141129
schema:
11151130
type: array
11161131
items:
11171132
type: string
11181133
style: form
11191134
explode: true
1135+
examples:
1136+
ObjectList:
1137+
dataValue: ["one thing", "another thing"]
1138+
serializedValue: "thing=one%20thing&thing=another%20thing"
11201139
```
11211140

1122-
A free-form query parameter, allowing undefined parameters of a specific type:
1141+
A free-form query parameter, allowing arbitrary parameters of a `type: "integer"`:
11231142
11241143
```yaml
11251144
in: query
@@ -1129,9 +1148,16 @@ schema:
11291148
additionalProperties:
11301149
type: integer
11311150
style: form
1151+
examples:
1152+
Pagination:
1153+
dataValue: {
1154+
"page": 4,
1155+
"pageSize": 50
1156+
}
1157+
serializeValue: page=4&pageSize=50
11321158
```
11331159
1134-
A complex parameter using `content` to define serialization:
1160+
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:
11351161

11361162
```yaml
11371163
in: query
@@ -1148,32 +1174,96 @@ content:
11481174
type: number
11491175
long:
11501176
type: number
1177+
examples:
1178+
dataValue: {
1179+
"lat": 10,
1180+
"long": 60
1181+
}
1182+
serializedValue: '{"lat":10,"long":60}'
1183+
examples:
1184+
dataValue: {
1185+
"lat": 10,
1186+
"long": 60
1187+
}
1188+
serializedValue: coordinates=%7B%22lat%22%3A10%2C%22long%22%3A60%7D
1189+
```
1190+
1191+
A querystring parameter using regular form encoding, but managed with a Media Type Object.
1192+
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.
1193+
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:
1194+
1195+
```yaml
1196+
in: querystring
1197+
content:
1198+
application/x-www-form-urlencoded:
1199+
schema:
1200+
type: object
1201+
properties:
1202+
foo:
1203+
type: string
1204+
bar:
1205+
type: boolean
1206+
examples:
1207+
spacesAndPluses:
1208+
description: Note handling of spaces and "+" per media type.
1209+
dataValue:
1210+
foo: a + b
1211+
bar: true
1212+
serializedValue: foo=a+%2B+b&bar=true
1213+
examples:
1214+
spacesAndPluses:
1215+
description: |
1216+
Note that no additional percent encoding is done, as this
1217+
media type is URI query string-ready by definition.
1218+
dataValue:
1219+
foo: a + b
1220+
bar: true
1221+
serializedValue: foo=a+%2B+b&bar=true
11511222
```
11521223

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

11551228
```yaml
11561229
in: querystring
11571230
name: json
11581231
content:
11591232
application/json:
11601233
schema:
1161-
# Allow an arbitrary JSON object to keep
1162-
# the example simple
11631234
type: object
1164-
example: {
1235+
properties:
1236+
numbers:
1237+
type: array
1238+
items:
1239+
type: integer
1240+
flag:
1241+
type: [boolean, "null"]
1242+
examples:
1243+
TwoNoFlag:
1244+
description: Serialize with minimized whitespace
1245+
dataValue: {
1246+
"numbers": [1, 2],
1247+
"flag": null
1248+
}
1249+
serializedValue: '{"numbers":[1,2],"flag":null}'
1250+
examples:
1251+
TwoNoFlag:
1252+
dataValue: {
11651253
"numbers": [1, 2],
11661254
"flag": null
11671255
}
1256+
serializedValue: "%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D"
11681257
```
11691258

1170-
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:
1259+
Assuming a path of `/foo`, a server of `https://example.com`, the full URL incorporating the value from `serializedValue` would be:
11711260

11721261
```uri
11731262
https://example.com/foo?%7B%22numbers%22%3A%5B1%2C2%5D%2C%22flag%22%3Anull%7D
11741263
```
11751264

1176-
A querystring parameter that uses JSONPath:
1265+
A querystring parameter that uses JSONPath.
1266+
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:
11771267

11781268
```yaml
11791269
in: querystring
@@ -1183,11 +1273,14 @@ content:
11831273
schema:
11841274
type: string
11851275
example: $.a.b[1:1]
1276+
examples:
1277+
Selector:
1278+
serializedValue: "%24.a.b%5B1%3A1%5D"
11861279
```
11871280

11881281
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.
11891282

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

11921285
```uri
11931286
https://example.com/foo?%24.a.b%5B1%3A1%5D
@@ -2545,6 +2638,7 @@ ETag:
25452638
schema:
25462639
type: string
25472640
pattern: ^"
2641+
example: xyzzx
25482642
```
25492643

25502644
#### Tag Object

0 commit comments

Comments
 (0)