Skip to content

Commit aa33fda

Browse files
committed
Support nested Encoding Objects
This adds the Media Type Object's encoding field to the Encoding Object to support nested multipart documents. It only requires one level of nesting, but allows implementations to support more.
1 parent 22fbdc9 commit aa33fda

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

src/oas.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,9 @@ These fields MAY be used either with or without the RFC6570-style serialization
16411641
| ---- | :----: | ---- |
16421642
| <a name="encoding-content-type"></a>contentType | `string` | The `Content-Type` for encoding a specific property. The value is a comma-separated list, each element of which is either a specific media type (e.g. `image/png`) or a wildcard media type (e.g. `image/*`). Default value depends on the property type as shown in the table below. |
16431643
| <a name="encoding-headers"></a>headers | Map[`string`, [Header Object](#header-object) \| [Reference Object](#reference-object)] | A map allowing additional information to be provided as headers. `Content-Type` is described separately and SHALL be ignored in this section. This field SHALL be ignored if the media type is not a `multipart`. |
1644+
| <a name="encoding-encoding"></a>encoding | Map[`string`, [Encoding Object](#encoding-object)] | Applies nested Encoding Objects in the same manner as the [Media Type Object](#media-type-object)'s `encoding` field. |
1645+
| <a name="encoding-prefix-encoding"></a>prefixEncoding | [[Encoding Object](#encoding-object)] | Applies nested Encoding Objects in the same manner as the [Media Type Object](#media-type-object)'s `prefixEncoding` field. |
1646+
| <a name="encoding-item-encoding"></a>itemEncoding | [Encoding Object](#encoding-object) | Applies nested Encoding Objects in the same manner as the [Media Type Object](#media-type-object)'s `itemEncoding` field. |
16441647

16451648
This object MAY be extended with [Specification Extensions](#specification-extensions).
16461649

@@ -1674,6 +1677,12 @@ See also [Appendix C: Using RFC6570 Implementations](#appendix-c-using-rfc6570-b
16741677
Note that the presence of at least one of `style`, `explode`, or `allowReserved` with an explicit value is equivalent to using `schema` with `in: "query"` Parameter Objects.
16751678
The absence of all three of those fields is the equivalent of using `content`, but with the media type specified in `contentType` rather than through a Media Type Object.
16761679

1680+
##### Nested Encoding
1681+
1682+
Nested formats requiring encoding, most notably nested `multipart/mixed`, can be supported with this Object's `encoding`, `prefixEncoding`, and / or `itemEncoding` fields.
1683+
Implementations MUST support one level of nesting, and MAY support additional levels.
1684+
If supporting additional levels, any limits on nesting levels MUST be documented.
1685+
16771686
##### Encoding the `x-www-form-urlencoded` Media Type
16781687

16791688
To work with content using form url encoding via [RFC1866](https://tools.ietf.org/html/rfc1866), use the `application/x-www-form-urlencoded` media type in the [Media Type Object](#media-type-object).
@@ -1869,6 +1878,30 @@ requestBody:
18691878

18701879
As seen in the [Encoding Object's `contentType` field documentation](#encoding-content-type), the empty schema for `items` indicates a media type of `application/octet-stream`.
18711880

1881+
###### Example: Nested `multipart/mixed`
1882+
1883+
This defines a two-part `multipart/mixed` where the first part is JSON and the second part is a nested `multipart/mixed` document.
1884+
The nested parts are JSON, plain text, and a PNG image.
1885+
1886+
```yaml
1887+
multipart/mixed:
1888+
schema:
1889+
type: array
1890+
prefixItems:
1891+
- type: array
1892+
- prefixItems:
1893+
- type: object
1894+
- type: string
1895+
- {}
1896+
prefixEncoding:
1897+
- {} # Accept the default application/json
1898+
- contentType: multipart/mixed
1899+
prefixEncoding:
1900+
- contentType: application/xml
1901+
- {} # Accept the default text/plain
1902+
- contentType: image/png
1903+
```
1904+
18721905
#### Responses Object
18731906

18741907
A container for the expected responses of an operation.

src/schemas/validation/schema.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,24 @@ $defs:
561561
allowReserved:
562562
default: false
563563
type: boolean
564+
encoding:
565+
type: object
566+
additionalProperties:
567+
$ref: '#/$defs/encoding'
568+
prefixEncoding:
569+
type: array
570+
items:
571+
$ref: '#/$defs/encoding'
572+
itemEncoding:
573+
$ref: '#/$defs/encoding'
564574
allOf:
565575
- $ref: '#/$defs/specification-extensions'
566576
- $ref: '#/$defs/styles-for-form'
577+
- dependentSchemas:
578+
encoding:
579+
properties:
580+
prefixEncoding: false
581+
itemEncoding: false
567582
unevaluatedProperties: false
568583

569584
responses:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: 3.2.0
2+
info:
3+
title: API
4+
version: 1.0.0
5+
components:
6+
requestBodies:
7+
content:
8+
multipart/mixed:
9+
prefixEncoding:
10+
- contentType: multipart/mixed
11+
encoding: {}
12+
prefixEncoding: []
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: 3.2.0
2+
info:
3+
title: API
4+
version: 1.0.0
5+
components:
6+
requestBodies:
7+
content:
8+
multipart/mixed:
9+
prefixEncoding:
10+
- contentType: multipart/mixed
11+
encoding: {}
12+
itemEncoding: []

tests/schema/pass/media-type-examples.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ paths:
117117
type: string
118118
forCoverage2:
119119
type: string
120+
nested1:
121+
type: object
122+
nested2:
123+
type: array
120124
encoding:
121125
addresses:
122126
# require XML Content-Type in utf-8 encoding
@@ -138,3 +142,12 @@ paths:
138142
forCoverage2:
139143
style: spaceDelimited
140144
explode: true
145+
nested1:
146+
contentType: multipart/form-data
147+
encoding:
148+
inner: {}
149+
nested2:
150+
contentType: multipart/mixed
151+
prefixEncoding:
152+
- {}
153+
itemEncoding: {}

0 commit comments

Comments
 (0)