Skip to content

Commit 22e5582

Browse files
authored
Merge pull request #4747 from handrews/nested-multi
2 parents 45d844c + 767bdaf commit 22e5582

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
@@ -1648,6 +1648,9 @@ These fields MAY be used either with or without the RFC6570-style serialization
16481648
| ---- | :----: | ---- |
16491649
| <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. |
16501650
| <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`. |
1651+
| <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. |
1652+
| <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. |
1653+
| <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. |
16511654

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

@@ -1681,6 +1684,11 @@ See also [Appendix C: Using RFC6570 Implementations](#appendix-c-using-rfc6570-b
16811684
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.
16821685
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.
16831686

1687+
##### Nested Encoding
1688+
1689+
Nested formats requiring encoding, most notably nested `multipart/mixed`, can be supported with this Object's `encoding`, `prefixEncoding`, and / or `itemEncoding` fields.
1690+
Implementations MUST support one level of nesting, and MAY support additional levels.
1691+
16841692
##### Encoding the `x-www-form-urlencoded` Media Type
16851693

16861694
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).
@@ -1885,6 +1893,31 @@ requestBody:
18851893

18861894
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`.
18871895

1896+
###### Example: Nested `multipart/mixed`
1897+
1898+
This defines a two-part `multipart/mixed` where the first part is a JSON array and the second part is a nested `multipart/mixed` document.
1899+
The nested parts are XML, plain text, and a PNG image.
1900+
1901+
```yaml
1902+
multipart/mixed:
1903+
schema:
1904+
type: array
1905+
prefixItems:
1906+
- type: array
1907+
- type: array
1908+
prefixItems:
1909+
- type: object
1910+
- type: string
1911+
- {}
1912+
prefixEncoding:
1913+
- {} # Accept the default application/json
1914+
- contentType: multipart/mixed
1915+
prefixEncoding:
1916+
- contentType: application/xml
1917+
- {} # Accept the default text/plain
1918+
- contentType: image/png
1919+
```
1920+
18881921
#### Responses Object
18891922

18901923
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
@@ -577,9 +577,24 @@ $defs:
577577
allowReserved:
578578
default: false
579579
type: boolean
580+
encoding:
581+
type: object
582+
additionalProperties:
583+
$ref: '#/$defs/encoding'
584+
prefixEncoding:
585+
type: array
586+
items:
587+
$ref: '#/$defs/encoding'
588+
itemEncoding:
589+
$ref: '#/$defs/encoding'
580590
allOf:
581591
- $ref: '#/$defs/specification-extensions'
582592
- $ref: '#/$defs/styles-for-form'
593+
- dependentSchemas:
594+
encoding:
595+
properties:
596+
prefixEncoding: false
597+
itemEncoding: false
583598
unevaluatedProperties: false
584599

585600
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
@@ -127,6 +127,10 @@ paths:
127127
type: string
128128
forCoverage2:
129129
type: string
130+
nested1:
131+
type: object
132+
nested2:
133+
type: array
130134
encoding:
131135
addresses:
132136
# require XML Content-Type in utf-8 encoding
@@ -148,3 +152,12 @@ paths:
148152
forCoverage2:
149153
style: spaceDelimited
150154
explode: true
155+
nested1:
156+
contentType: multipart/form-data
157+
encoding:
158+
inner: {}
159+
nested2:
160+
contentType: multipart/mixed
161+
prefixEncoding:
162+
- {}
163+
itemEncoding: {}

0 commit comments

Comments
 (0)