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
This adds support for all `multipart` media types that do not
have named parts, including support for streaming such media types.
Note that `multipart/mixed` defines the basic processing rules
for all `multipart` types, and implementations that encounter
unrecognized `multipart` subtypes are required to process them
as `multipart/mixed`. Therefore support for `multipart/mixed`
addresses all other subtypes to some degree.
This builds on the recent support for sequential media types:
* `multipart/mixed` and similar meet the definition for
a sequential media type, requiring it to be modeled as
an array. This does use an expansive definition of
"repeating the same structure", where the structure is
literally any content with a media type.
* As a sequential media type, it also supports `itemSchema`
* Adding a parallel `itemEncoding` is the obvious solution to
`multipart/mixed` streams requiring an Encoding Object
* We have regularly received requests to support truly mixed
`multipart/mixed` payloads, and previously claimed such support
from 3.0.0 onwards, without actually supporting it.
Adding `prefixEncoding` along with `itemEncoding` supports this
use case with a clear parallel to `prefixItems`, which is the
schema construct needed to support this case.
* There is no need for a `prefixSchema` field because the streaming
use case requires a repetition of the same schema for each item.
Therefore all mixed use cases can use `schema` and `prefixItems`
Copy file name to clipboardExpand all lines: src/oas.md
+39-14Lines changed: 39 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -101,14 +101,18 @@ Some examples of sequential media types (including some that are not IANA-regist
101
101
application/json-seq
102
102
application/geo+json-seq
103
103
text/event-stream
104
+
multipart/mixed
104
105
```
105
106
106
107
In the first three above, the repeating structure is any [JSON value](https://tools.ietf.org/html/rfc8259#section-3).
107
-
The fourth repeats `application/geo+json`-structured values, while the last repeats a custom text format related to Server-Sent Events.
108
+
The fourth repeats `application/geo+json`-structured values, while `text/event-stream` repeats a custom text format related to Server-Sent Events.
109
+
The final media type listed above, `multipart/mixed`, provides an ordered list of documents of any media type, and is sometimes streamed.
110
+
Note that while `multipart` formats technically allow a preamble and an epilogue, the RFC directs that they are to be ignored, making them effectively comments, and this specification does not model them.
108
111
109
112
Implementations MUST support mapping sequential media types into the JSON Schema data model by treating them as if the values were in an array in the same order.
110
113
111
114
See [Complete vs Streaming Content](#complete-vs-streaming-content) for more information on handling sequential media types in a streaming context, including special considerations for `text/event-stream` content.
115
+
For `multipart` types, see also [Encoding By Position](#encoding-by-position).
112
116
113
117
#### Media Type Registry
114
118
@@ -1253,7 +1257,9 @@ See [Working With Examples](#working-with-examples) for further guidance regardi
1253
1257
| <a name="media-type-item-schema"></a>itemSchema | [Schema Object](#schema-object) | A schema describing each item within a [sequential media type](#sequential-media-types). |
1254
1258
| <a name="media-type-example"></a>example | Any | Example of the media type; see [Working With Examples](#working-with-examples). |
1255
1259
| <a name="media-type-examples"></a>examples | Map[ `string`, [Example Object](#example-object) \| [Reference Object](#reference-object)] | Examples of the media type; see [Working With Examples](#working-with-examples). |
1256
-
| <a name="media-type-encoding"></a>encoding | Map[`string`, [Encoding Object](#encoding-object)] | A map between a property name and its encoding information, as defined under [Encoding Usage and Restrictions](#encoding-usage-and-restrictions). The `encoding` field SHALL only apply when the media type is `multipart` or `application/x-www-form-urlencoded`. If no Encoding Object is provided for a property, the behavior is determined by the default values documented for the Encoding Object. |
1260
+
| <a name="media-type-encoding"></a>encoding | Map[`string`, [Encoding Object](#encoding-object)] | A map between a property name and its encoding information, as defined under [Encoding By Name](#encoding-by-name). The `encoding` field SHALL only apply when the media type is `multipart` or `application/x-www-form-urlencoded`. If no Encoding Object is provided for a property, the behavior is determined by the default values documented for the Encoding Object. This field MUST NOT be present if `prefixEncoding` or `itemEncoding` are present. |
1261
+
| <a name="media-type-prefix-encoding"></a>prefixEncoding | [[Encoding Object](#encoding-object)] | An array of positional encoding information, as defined under [Encoding By Position](#encoding-by-position). The `prefixEncoding` field SHALL only apply when the media type is `multipart`. If no Encoding Object is provided for a property, the behavior is determined by the default values documented for the Encoding Object. This field MUST NOT be present if `encoding` is present. |
1262
+
| <a name="media-type-item-encoding"></a>itemEncoding | [Encoding Object](#encoding-object) | A single Encoding Object that provides encoding information for multiple array items, as defined under [Encoding By Position](#encoding-by-position). The `itemEncoding` field SHALL only apply when the media type is `multipart`. If no Encoding Object is provided for a property, the behavior is determined by the default values documented for the Encoding Object. This field MUST NOT be present if `encoding` is present. |
1257
1263
1258
1264
This object MAY be extended with [Specification Extensions](#specification-extensions).
1259
1265
@@ -1273,7 +1279,8 @@ For this use case, `maxLength` MAY be implemented outside of regular JSON Schema
1273
1279
1274
1280
###### Streaming Sequential Media Types
1275
1281
1276
-
The `itemSchema` field is provided to support streaming use cases for sequential media types.
1282
+
The `itemSchema` field is provided to support streaming use cases for sequential media types, with `itemEncoding` as a corresponding encoding mechanism for streaming [positional `multipart` media types](#encoding-by-position).
1283
+
1277
1284
Unlike `schema`, which is applied to the complete content (treated as an array as described in the [sequential media types](#sequential-media-types) section), `itemSchema` MUST be applied to each item in the stream independently, which supports processing each item as it is read from the stream.
1278
1285
1279
1286
Both `schema` and `itemSchema` MAY be used in the same Media Type Object.
@@ -1309,13 +1316,16 @@ properties:
1309
1316
1310
1317
##### Encoding Usage and Restrictions
1311
1318
1312
-
The `encoding` field defines how to map each [Encoding Object](#encoding-object) to a specific value in the data.
1319
+
The three encoding fields define how to map each [Encoding Object](#encoding object) to a specific value in the data.
1320
+
Each field has its own set of media types with which it can be used; for all other media types all three fields SHALL be ignored.
1313
1321
1314
-
To use the `encoding` field, a `schema` MUST exist, and the `encoding` field's keys MUST exist in the schema as properties.
1315
-
Array properties MUST be handled by applying the given Encoding Object to one part per array item, each with the same `name`, as is recommended by [[?RFC7578]] [Section 4.3](https://www.rfc-editor.org/rfc/rfc7578.html#section-4.3) for supplying multiple values per form field.
1316
-
For all other value types for both top-level non-array properties and for values, including array values, within a top-level array, the Encoding Object MUST be applied to the entire value.
1322
+
###### Encoding By Name
1317
1323
1318
1324
The behavior of the `encoding` field is designed to support web forms, and is therefore only defined for media types structured as name-value pairs that allow repeat values, most notably `application/x-www-form-urlencoded` and `multipart/form-data`.
1325
+
1326
+
To use the `encoding` field, each key under the field MUST exist in the `schema` as a property.
1327
+
Array properties MUST be handled by applying the given Encoding Object to produce one encoded value per array item, each with the same `name`, as is recommended by [[?RFC7578]] [Section 4.3](https://www.rfc-editor.org/rfc/rfc7578.html#section-4.3) for supplying multiple values per form field.
1328
+
For all other value types for both top-level non-array properties and for values, including array values, within a top-level array, the Encoding Object MUST be applied to the entire value.
1319
1329
The order of these name-value pairs in the target media type is implementation-defined.
1320
1330
1321
1331
For `application/x-www-form-urlencoded`, the encoding keys MUST map to parameter names, with the values produced according to the rules of the [Encoding Object](#encoding-object).
@@ -1324,15 +1334,29 @@ See [Encoding the `x-www-form-urlencoded` Media Type](#encoding-the-x-www-form-u
1324
1334
For `multipart`, the encoding keys MUST map to the [`name` parameter](https://www.rfc-editor.org/rfc/rfc7578#section-4.2) of the `Content-Disposition: form-data` header of each part, as is defined for `multipart/form-data` in [[?RFC7578]].
1325
1335
See [[?RFC7578]] [Section 5](https://www.rfc-editor.org/rfc/rfc7578.html#section-5) for guidance regarding non-ASCII part names.
1326
1336
1327
-
Other `multipart` media types are not directly supported as they do not define a mechanism for part names.
1328
-
However, the usage of a `name` [`Content-Disposition` parameter](https://www.iana.org/assignments/cont-disp/cont-disp.xhtml#cont-disp-2) is defined for the `form-data` [`Content-Disposition` value](https://www.iana.org/assignments/cont-disp/cont-disp.xhtml#cont-disp-1), which is not restricted to `multipart/form-data`.
1329
-
Implementations MAY choose to support the a `Conent-Disposition` of `form-data` with a `name` parameter in other `multipart` media types in order to use the `encoding` field with them, but this usage is unlikely to be supported by generic `multipart` implementations.
1330
-
1331
1337
See [Encoding `multipart` Media Types](#encoding-multipart-media-types) for further guidance and examples, both with and without the `encoding` field.
1332
1338
1339
+
###### Encoding By Position
1340
+
1341
+
Most `multipart` media types, including `multipart/mixed` which defines the underlying rules for parsing all `multipart` types, do not have named parts.
1342
+
Data for these media types are modeled as an array, with one item per part, in order.
1343
+
1344
+
To use the `prefixEncoding` and/or `itemEncoding` fields, either `itemSchema` or an array `schema` MUST be present.
1345
+
These fields are analogous to the `prefixItems` and `items` JSON Schema keywords, with `prefixEncoding` (if present) providing an array of Encoding Objects that are each applied to the value at the same position in the data array, and `itemEncoding` applying its single Encoding Object to all remaining items in the array.
1346
+
1347
+
The `itemEncoding` field can also be used with `itemSchema` to support streaming `multipart` content.
1348
+
1349
+
###### Additional Encoding Approaches
1350
+
1351
+
The `prefixEncoding` field can be used with any `multipart` content to require a fixed part order.
1352
+
This includes `multipart/form-data`, for which the Encoding Object's `headers` field MUST be used to provide the `Content-Disposition` and part name, as no property names exist to provide the names automatically.
1353
+
1354
+
Prior versions of this specification advised using the `name` [`Content-Disposition` parameter](https://www.iana.org/assignments/cont-disp/cont-disp.xhtml#cont-disp-2) of the `form-data` [`Content-Disposition` value](https://www.iana.org/assignments/cont-disp/cont-disp.xhtml#cont-disp-1) with `multipart` media types other than `multipart/form-data` in order to work around the limitations of the `encoding` field.
1355
+
Implementations MAY choose to support this workaround, but as this usage is not common, implementations of non-`form-data` `multipart` media types are unlikely to support it.
1356
+
1333
1357
##### Media Type Examples
1334
1358
1335
-
For form-related media type examples, see the [Encoding Object](#encoding-object).
1359
+
For form-related and `multipart` media type examples, see the [Encoding Object](#encoding-object).
1336
1360
1337
1361
###### JSON
1338
1362
@@ -1645,8 +1669,9 @@ These fields MAY be used either with or without the RFC6570-style serialization
1645
1669
This object MAY be extended with [Specification Extensions](#specification-extensions).
1646
1670
1647
1671
The default values for `contentType` are as follows, where an _n/a_ in the `contentEncoding` column means that the presence or value of `contentEncoding` is irrelevant.
1648
-
This table is based on the value to which the Encoding Object is being applied, which as defined under [Encoding Usage and Restrictions](#encoding-usage-and-restrictions) is the array item for properties of type `"array"`, and the entire value for all other types.
1649
-
Therefore the `array` row in this table applies only to array values inside of a top-level array.
1672
+
This table is based on the value to which the Encoding Object is being applied as defined under [Encoding Usage and Restrictions](#encoding-usage-and-restrictions).
1673
+
Note that in the case of [Encoding By Name](#encoding-by-name), this value is the array item for properties of type `"array"`, and the entire value for all other types.
1674
+
Therefore the `array` row in this table applies only to array values inside of a top-level array when encoding by name.
0 commit comments