You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
This also shows some uses of the new Example Object fields,
including some that would be redundant but are included to
clarify the different options; the redundancy is noted in the text.
Copy file name to clipboardExpand all lines: src/oas.md
+27-9Lines changed: 27 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1030,23 +1030,41 @@ In order to support common ways of serializing simple parameters, a set of `styl
1030
1030
1031
1031
See [Appendix E](#appendix-e-percent-encoding-and-form-media-types) for a discussion of percent-encoding, including when delimiters need to be percent-encoded and options for handling collisions with percent-encoded data.
1032
1032
1033
+
##### Serialization and Examples
1034
+
1035
+
The rules in this section apply to both the Parameter and [Header](#header-object) Objects, both of which use the same mechanisms.
1036
+
1037
+
When showing serialized examples, such as with the [Example Object's](#example-object) `serializedValue` or `externalValue` fields, 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.
1038
+
1039
+
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.
1040
+
1041
+
The `matrix` and `label` styles produce a leading delimiter which is always a valid part of the serialization and MUST be included.
1042
+
The RFC6570 operators corresponding to `style: "form"` produces a leading delimiter of either `?` or `&` depending on the exact syntax used.
1043
+
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.
1044
+
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.
1045
+
1046
+
For headers, the header name MUST NOT be included as part of the serialization, as it is never part of the RFC6570-derived result.
1047
+
However, names produced by `style: "simple", explode: "true"` are included as they appear within the header value, not as separate headers.
1048
+
See the [Header Object](#header-object) for special rules for showing examples of the `Set-Cookie` response header, which violates the normal rules for multiple header values.
1049
+
1050
+
The following section illustrates these rules.
1051
+
1033
1052
##### Style Examples
1034
1053
1035
-
Assume a parameter named `color` has one of the following values:
1054
+
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:
1036
1055
1037
1056
```js
1038
1057
string -> "blue"
1039
1058
array -> ["blue", "black", "brown"]
1040
1059
object -> { "R": 100, "G": 200, "B": 150 }
1041
1060
```
1042
1061
1043
-
The following table shows examples, as would be shown with the `example` or `examples` keywords, of the different serializations for each value.
1062
+
The following table shows serialized examples, as would be shown with the `serializedValue` field of an Example Object, of the different serializations for each value.
1044
1063
1045
1064
* The value _empty_ denotes the empty string, and is unrelated to the `allowEmptyValue` field
1046
1065
* The behavior of combinations marked _n/a_ is undefined
1047
1066
* 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
1048
-
* 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
1049
-
* 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
1067
+
* 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
1050
1068
* 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.
0 commit comments