Skip to content

Commit 151841c

Browse files
committed
Explain Param and Header example serialization
The rules for this have not been clear, and are not always intuitive. This states and explains them directly and ensures that the Style Examples table matches the rules. Unlike past efforts, this provides a rule system regarding what is and is not included, based on a combination of what is produced by RFC6570 (or the nearest RFC6570 equivalent), modified by removing leading delimiters that are not correct for our usage due to differences from the assuptions made by RFC6570.
1 parent 428b75e commit 151841c

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/oas.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,23 +1230,40 @@ In some cases, such as inserting `/` into path parameter values, doing so is [ex
12301230

12311231
See [Appendix E](#appendix-e-percent-encoding-and-form-media-types) for a thorough discussion of percent-encoding options, compatibility, and OAS-defined delimiters that are not allowed by RFC3986, and [Appendix C](#appendix-c-using-rfc6570-based-serialization) for guidance on using RFC6570 implementations.
12321232

1233+
##### Serialization and Examples
1234+
1235+
The rules in this section apply to both the Parameter and [Header](#header-object) Objects, both of which use the same mechanisms.
1236+
1237+
When showing serialized examples using the `example` field or [Example Objects](#example-object), in most cases the value to show is just the value, with all relevant percent-encoding or other encoding/escaping applied, and also including any delimiters produced by the `style` and `explode` configuration.
1238+
1239+
In cases where the name is an inherent part of constructing the serialization, such as the `name=value` pairs produced by `style: "form"` or the combination of `style: "simple", explode: true`, the name and any delimiter between the name and value MUST be included.
1240+
1241+
The `matrix` and `label` styles produce a leading delimiter which is always a valid part of the serialization and MUST be included.
1242+
The RFC6570 operators corresponding to `style: "form"` produce a leading delimiter of either `?` or `&` depending on the exact syntax used.
1243+
As the suitability of either delimiter depends on where in the query string the parameter occurs, as well as whether it is in a URI or in `application/x-www-form-urlencoded` content, this leading delimiter MUST NOT be included in examples of individual parameters or media type documents.
1244+
For `in: "cookie", style: "form"`, neither the `&` nor `?` delimiters are ever correct; see [Appendix D: Serializing Headers and Cookies](#appendix-d-serializing-headers-and-cookies) for more details.
1245+
1246+
For headers, the header name MUST NOT be included as part of the serialization, as it is never part of the RFC6570-derived result.
1247+
However, names produced by `style: "simple", explode: "true"` are included as they appear within the header value, not as separate headers.
1248+
1249+
The following section illustrates these rules.
1250+
12331251
##### Style Examples
12341252

1235-
Assume a parameter named `color` has one of the following values:
1253+
Assume a parameter named `color` has one of the following values, where the value to the right of the `->` is what would be shown in the `dataValue` field of an Example Object:
12361254

12371255
```js
12381256
string -> "blue"
12391257
array -> ["blue", "black", "brown"]
12401258
object -> { "R": 100, "G": 200, "B": 150 }
12411259
```
12421260

1243-
The following table shows examples, as would be shown with the `example` or `examples` keywords, of the different serializations for each value.
1261+
The following table shows serialized examples, as would be shown with the `example` or `examples` keywords, of the different serializations for each value.
12441262

1245-
* The value _empty_ denotes the empty string, and is unrelated to the `allowEmptyValue` field
1246-
* The behavior of combinations marked _n/a_ is undefined
1247-
* The `undefined` column replaces the `empty` column in previous versions of this specification in order to better align with [RFC6570](https://www.rfc-editor.org/rfc/rfc6570.html#section-2.3) terminology, which describes certain values including but not limited to `null` as "undefined" values with special handling; notably, the empty string is _not_ undefined
1248-
* For `form` and the non-RFC6570 query string styles `spaceDelimited`, `pipeDelimited`, and `deepObject`, each example is shown prefixed with `?` as if it were the only query parameter; see [Appendix C](#appendix-c-using-rfc6570-based-serialization) for more information on constructing query strings from multiple parameters, and [Appendix D](#appendix-d-serializing-headers-and-cookies) for warnings regarding `form` and cookie parameters
1249-
* Note that the `?` prefix is not appropriate for serializing `application/x-www-form-urlencoded` HTTP message bodies, and MUST be stripped or (if constructing the string manually) not added when used in that context; see the [Encoding Object](#encoding-object) for more information
1263+
* The value _empty_ denotes the empty string, and is unrelated to the `allowEmptyValue` field.
1264+
* The behavior of combinations marked _n/a_ is undefined.
1265+
* The `undefined` column replaces the `empty` column in previous versions of this specification in order to better align with [RFC6570](https://www.rfc-editor.org/rfc/rfc6570.html#section-2.3) terminology, which describes certain values including but not limited to `null` as "undefined" values with special handling; notably, the empty string is _not_ undefined.
1266+
* For `form` and the non-RFC6570 query string styles `spaceDelimited`, `pipeDelimited`, and `deepObject`, see [Appendix C](#appendix-c-using-rfc6570-based-serialization) for more information on constructing query strings from multiple parameters, and [Appendix D](#appendix-d-serializing-headers-and-cookies) for warnings regarding `form` and cookie parameters.
12501267
* The examples are percent-encoded as required by RFC6570 and RFC3986; see [Appendix E](#appendix-e-percent-encoding-and-form-media-types) for a thorough discussion of percent-encoding concerns, including why unencoded `|` (`%7C`), `[` (`%5B`), and `]` (`%5D`) seem to work in some environments despite not being compliant.
12511268

12521269
| [`style`](#style-values) | `explode` | `undefined` | `string` | `array` | `object` |
@@ -1257,14 +1274,14 @@ The following table shows examples, as would be shown with the `example` or `exa
12571274
| label | true | . | .blue | .blue.black.brown | .R=100.G=200.B=150 |
12581275
| simple | false | _empty_ | blue | blue,black,brown | R,100,G,200,B,150 |
12591276
| simple | true | _empty_ | blue | blue,black,brown | R=100,G=200,B=150 |
1260-
| form | false | <span style="white-space: nowrap;">?color=</span> | <span style="white-space: nowrap;">?color=blue</span> | <span style="white-space: nowrap;">?color=blue,black,brown</span> | <span style="white-space: nowrap;">?color=R,100,G,200,B,150</span> |
1261-
| form | true | <span style="white-space: nowrap;">?color=</span> | <span style="white-space: nowrap;">?color=blue</span> | <span style="white-space: nowrap;">?color=blue&color=black&color=brown</span> | <span style="white-space: nowrap;">?R=100&G=200&B=150</span> |
1262-
| spaceDelimited</span> | false | _n/a_ | _n/a_ | <span style="white-space: nowrap;">?color=blue%20black%20brown</span> | <span style="white-space: nowrap;">?color=R%20100%20G%20200%20B%20150</span> |
1277+
| form | false | <span style="white-space: nowrap;">color=</span> | <span style="white-space: nowrap;">color=blue</span> | <span style="white-space: nowrap;">color=blue,black,brown</span> | <span style="white-space: nowrap;">color=R,100,G,200,B,150</span> |
1278+
| form | true | <span style="white-space: nowrap;">color=</span> | <span style="white-space: nowrap;">color=blue</span> | <span style="white-space: nowrap;">color=blue&color=black&color=brown</span> | <span style="white-space: nowrap;">R=100&G=200&B=150</span> |
1279+
| spaceDelimited</span> | false | _n/a_ | _n/a_ | <span style="white-space: nowrap;">color=blue%20black%20brown</span> | <span style="white-space: nowrap;">color=R%20100%20G%20200%20B%20150</span> |
12631280
| spaceDelimited | true | _n/a_ | _n/a_ | _n/a_ | _n/a_ |
1264-
| pipeDelimited | false | _n/a_ | _n/a_ | <span style="white-space: nowrap;">?color=blue%7Cblack%7Cbrown</span> | <span style="white-space: nowrap;">?color=R%7C100%7CG%7C200%7CB%7C150</span> |
1281+
| pipeDelimited | false | _n/a_ | _n/a_ | <span style="white-space: nowrap;">color=blue%7Cblack%7Cbrown</span> | <span style="white-space: nowrap;">color=R%7C100%7CG%7C200%7CB%7C150</span> |
12651282
| pipeDelimited | true | _n/a_ | _n/a_ | _n/a_ | _n/a_ |
12661283
| deepObject | false | _n/a_ | _n/a_ | _n/a_ | _n/a_ |
1267-
| deepObject | true | _n/a_ | _n/a_ | _n/a_ | <span style="white-space: nowrap;">?color%5BR%5D=100&color%5BG%5D=200&color%5BB%5D=150</span> |
1284+
| deepObject | true | _n/a_ | _n/a_ | _n/a_ | <span style="white-space: nowrap;">color%5BR%5D=100&color%5BG%5D=200&color%5BB%5D=150</span> |
12681285

12691286
##### Parameter Object Examples
12701287

0 commit comments

Comments
 (0)