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
Parameter and Header serialization is complex, particularly when
using the `content` field to use a Media Type Object.
In such scenarios, the serialization occurs in two steps:
The first step is to serialize the data to the media type, which
can be captured by the `examples` field of the Media Type Object.
The second is the encoding/escaping of the media type document
for use in a URI, HTTP header, or other location with its own rules.
Sometimes the part needing illustration with an example is at one
level, sometimes at another, and sometimes it is helpful to show
both.
For simplicity, the "data" examples are always treated as the
overall input data, so they would be the same at both levels.
This is also because it is not always possible to show each step,
particularly when there are binary serializations. This allows
showing either step (or both steps) with both data and serialization,
depending on what makes sense for the use case.
Copy file name to clipboardExpand all lines: src/oas.md
+58-11Lines changed: 58 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -964,6 +964,7 @@ See [Appendix B](#appendix-b-data-type-conversion) for a discussion of convertin
964
964
###### Common Fixed Fields
965
965
966
966
These fields MAY be used with either `content` or `schema`.
967
+
The `example` and `examples` fields are mutually exclusive, and if either is present it SHALL _override_ any `example` in the schema.
967
968
968
969
| Field Name | Type | Description |
969
970
| ---- | :----: | ---- |
@@ -973,6 +974,8 @@ These fields MAY be used with either `content` or `schema`.
973
974
| <a name="parameter-required"></a>required | `boolean` | Determines whether this parameter is mandatory. If the [parameter location](#parameter-in) is `"path"`, this field is **REQUIRED** and its value MUST be `true`. Otherwise, the field MAY be included and its default value is `false`. |
974
975
| <a name="parameter-deprecated"></a> deprecated | `boolean` | Specifies that a parameter is deprecated and SHOULD be transitioned out of usage. Default value is `false`. |
975
976
| <a name="parameter-allow-empty-value"></a> allowEmptyValue | `boolean` | If `true`, clients MAY pass a zero-length string value in place of parameters that would otherwise be omitted entirely, which the server SHOULD interpret as the parameter being unused. Default value is `false`. If [`style`](#parameter-style) is used, and if [behavior is _n/a_ (cannot be serialized)](#style-examples), the value of `allowEmptyValue` SHALL be ignored. Interactions between this field and the parameter's [Schema Object](#schema-object) are implementation-defined. This field is valid only for `query` parameters. <br><br>**Deprecated:** Use of this field is NOT RECOMMENDED, and it is likely to be removed in a later revision. |
977
+
| <a name="parameter-example"></a>example | Any | Example of the parameter's potential value; see [Working With Examples](#working-with-examples). |
978
+
| <a name="parameter-examples"></a>examples | Map[ `string`, [Example Object](#example-object) \| [Reference Object](#reference-object)] | Examples of the parameter's potential value; see [Working With Examples](#working-with-examples). |
976
979
977
980
This object MAY be extended with [Specification Extensions](#specification-extensions).
978
981
@@ -982,7 +985,6 @@ Note that while `"Cookie"` as a `name` is not forbidden if `in` is `"header"`, t
982
985
983
986
For simpler scenarios, a [`schema`](#parameter-schema) and [`style`](#parameter-style) can describe the structure and syntax of the parameter.
984
987
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the parameter.
985
-
The `example` and `examples` fields are mutually exclusive, and if either is present it SHALL _override_ any `example` in the schema.
986
988
987
989
These fields MUST NOT be used with `in: "querystring"`.
988
990
@@ -994,8 +996,6 @@ Serializing with `schema` is NOT RECOMMENDED for `in: "cookie"` parameters, `in:
994
996
| <a name="parameter-explode"></a>explode | `boolean` | When this is true, parameter values of type `array` or `object` generate separate parameters for each value of the array or key-value pair of the map. For other types of parameters this field has no effect. When [`style`](#parameter-style) is `"form"`, the default value is `true`. For all other styles, the default value is `false`. Note that despite `false` being the default for `deepObject`, the combination of `false` with `deepObject` is undefined. |
995
997
| <a name="parameter-allow-reserved"></a>allowReserved | `boolean` | When this is true, parameter values are serialized using reserved expansion, as defined by [RFC6570](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.3), which allows [RFC3986's reserved character set](https://datatracker.ietf.org/doc/html/rfc3986#section-2.2), as well as percent-encoded triples, to pass through unchanged, while still percent-encoding all other disallowed characters (including `%` outside of percent-encoded triples). Applications are still responsible for percent-encoding reserved characters that are not allowed by the rules of the `in` destination or media type, or are [not allowed in the path by this specification](#path-templating); see Appendices [C](#appendix-c-using-rfc6570-based-serialization) and [E](#appendix-e-percent-encoding-and-form-media-types) for details. The default value is `false`. |
996
998
| <a name="parameter-schema"></a>schema | [Schema Object](#schema-object) | The schema defining the type used for the parameter. |
997
-
| <a name="parameter-example"></a>example | Any | Example of the parameter's potential value; see [Working With Examples](#working-with-examples). |
998
-
| <a name="parameter-examples"></a>examples | Map[ `string`, [Example Object](#example-object) \| [Reference Object](#reference-object)] | Examples of the parameter's potential value; see [Working With Examples](#working-with-examples). |
999
999
1000
1000
See also [Appendix C: Using RFC6570-Based Serialization](#appendix-c-using-rfc6570-based-serialization) for additional guidance.
1001
1001
@@ -1146,6 +1146,38 @@ content:
1146
1146
type: number
1147
1147
```
1148
1148
1149
+
A querystring parameter using regular form encoding, but managed with a Media Type Object:
1150
+
1151
+
```yaml
1152
+
in: querystring
1153
+
content:
1154
+
application/x-www-form-urlencoded:
1155
+
schema:
1156
+
type: object
1157
+
properties:
1158
+
foo:
1159
+
type: string
1160
+
bar:
1161
+
type: boolean
1162
+
examples:
1163
+
spacesAndPluses:
1164
+
description: Note handling of spaces and "+" per media type.
1165
+
dataValue:
1166
+
foo: a + b
1167
+
bar: true
1168
+
serializedValue:
1169
+
foo=a+%2B+b&bar=true
1170
+
examples:
1171
+
spacesAndPluses:
1172
+
description: |
1173
+
Note that no additional percent encoding is done, as this
1174
+
media type is URI query string-ready by definition.
1175
+
dataValue:
1176
+
foo: a + b
1177
+
bar: true
1178
+
serializedValue:
1179
+
foo=a+%2B+b&bar=true
1180
+
1149
1181
A querystring parameter that uses JSON for the entire string (not as a single query parameter value):
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:
1209
+
Assuming a path of `/foo`, a server of `https://example.com`, the full URL incorporating the value serialized as shown by the Example Objects would be:
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.
1185
1232
1186
-
Assuming a path of `/foo` and a server of `https://example.com`, the full URL incorporating the value from the `example` field would be:
1233
+
Assuming a path of `/foo` and a server of `https://example.com`, the full URL incorporating the value from the Example Object would be:
1187
1234
1188
1235
```uri
1189
1236
https://example.com/foo?%24.a.b%5B1%3A1%5D
@@ -2411,11 +2458,16 @@ The Header Object follows the structure of the [Parameter Object](#parameter-obj
2411
2458
2412
2459
These fields MAY be used with either `content` or `schema`.
2413
2460
2461
+
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the header.
2462
+
The `example` and `examples` fields are mutually exclusive, and if either is present it SHALL _override_ any `example` in the schema.
2463
+
2414
2464
| Field Name | Type | Description |
2415
2465
| ---- | :----: | ---- |
2416
2466
| <aname="header-description"></a>description |`string`| A brief description of the header. This could contain examples of use. [CommonMark syntax](https://spec.commonmark.org/) MAY be used for rich text representation. |
2417
2467
| <aname="header-required"></a>required |`boolean`| Determines whether this header is mandatory. The default value is `false`. |
2418
2468
| <aname="header-deprecated"></a> deprecated |`boolean`| Specifies that the header is deprecated and SHOULD be transitioned out of usage. Default value is `false`. |
2469
+
| <aname="header-example"></a>example | Any | Example of the header's potential value; see [Working With Examples](#working-with-examples). |
2470
+
| <aname="header-examples"></a>examples | Map[`string`, [Example Object](#example-object)\|[Reference Object](#reference-object)]| Examples of the header's potential value; see [Working With Examples](#working-with-examples). |
2419
2471
2420
2472
This object MAY be extended with [Specification Extensions](#specification-extensions).
2421
2473
@@ -2426,16 +2478,11 @@ When `example` or `examples` are provided in conjunction with the `schema` field
2426
2478
2427
2479
Serializing with `schema` is NOT RECOMMENDED for headers with parameters (name=value pairs following a `;`) in their values, or where values might have non-URL-safe characters; see [Appendix D](#appendix-d-serializing-headers-and-cookies) for details.
2428
2480
2429
-
When `example` or `examples` are provided in conjunction with the `schema` field, the example SHOULD match the specified schema and follow the prescribed serialization strategy for the header.
2430
-
The `example` and `examples` fields are mutually exclusive, and if either is present it SHALL _override_ any `example` in the schema.
2431
-
2432
2481
| Field Name | Type | Description |
2433
2482
| ---- | :----: | ---- |
2434
2483
| <aname="header-style"></a>style |`string`| Describes how the header value will be serialized. The default (and only legal value for headers) is `"simple"`. |
2435
2484
| <aname="header-explode"></a>explode |`boolean`| When this is true, header values of type `array` or `object` generate a single header whose value is a comma-separated list of the array items or key-value pairs of the map, see [Style Examples](#style-examples). For other data types this field has no effect. The default value is `false`. |
2436
2485
| <aname="header-schema"></a>schema |[Schema Object](#schema-object)\|[Reference Object](#reference-object)| The schema defining the type used for the header. |
2437
-
| <aname="header-example"></a>example | Any | Example of the header's potential value; see [Working With Examples](#working-with-examples). |
2438
-
| <aname="header-examples"></a>examples | Map[`string`, [Example Object](#example-object)\|[Reference Object](#reference-object)]| Examples of the header's potential value; see [Working With Examples](#working-with-examples). |
2439
2486
2440
2487
See also [Appendix C: Using RFC6570-Based Serialization](#appendix-c-using-rfc6570-based-serialization) for additional guidance.
0 commit comments