Skip to content

Commit 0b37bca

Browse files
committed
New encoding examples
1 parent 22e5582 commit 0b37bca

File tree

1 file changed

+93
-1
lines changed

1 file changed

+93
-1
lines changed

src/oas.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,99 @@ requestBody:
18931893

18941894
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`.
18951895

1896+
###### Example: Ordered, Unnamed Multipart
1897+
1898+
A `multipart/mixed` payload consisting of a JSON metadata document followed by an image which the metadata describes:
1899+
1900+
```yaml
1901+
multipart/mixed:
1902+
schema:
1903+
type: array
1904+
prefixItems:
1905+
- # default content type for objects
1906+
# is `application/json`
1907+
type: object
1908+
properties:
1909+
author:
1910+
type: string
1911+
created:
1912+
type: string
1913+
format: datetime
1914+
copyright:
1915+
type: string
1916+
license:
1917+
type: string
1918+
- # default content type for a schema without `type`
1919+
# is `application/octet-stream`, which we need
1920+
# to override.
1921+
{}
1922+
prefixEncoding:
1923+
- # Encoding Object defaults are correct for JSON
1924+
{}
1925+
- contentType: image/*
1926+
```
1927+
1928+
###### Example: Ordered Multipart With Required Header
1929+
1930+
As described in [[?RFC2557]], a set of HTML pages can be sent in a `multipart/related` payload, preserving links among themselves by defining a `Content-Location` header for each page.
1931+
1932+
See [Appendix D](appendix-d-serializing-headers-and-cookies) for an explanation of why `content: {text/plain: {...}}` is used to describe the header value.
1933+
1934+
```yaml
1935+
multipart/related:
1936+
schema:
1937+
items:
1938+
type: string
1939+
itemEncoding:
1940+
contentType: text/html
1941+
headers:
1942+
Content-Location:
1943+
required: true
1944+
content:
1945+
text/plain:
1946+
schema:
1947+
type: string
1948+
format: uri
1949+
```
1950+
1951+
While the above example could have used `itemSchema` instead, if the payload is expected to be processed all at once, using `schema` ensures that tools will wait until the complete response is available before processing.
1952+
1953+
###### Example: Streaming Multipart
1954+
1955+
This example assumes a device that takes large sets of pictures and streams them to the caller.
1956+
Unlike the previous example, we use `itemSchema` here because the expectation is that each image is processed as it arrives (or in small batches), since we know that buffering the entire stream will take too much memory.
1957+
1958+
```yaml
1959+
multipart/mixed:
1960+
itemSchema:
1961+
$comment: A single data image from the device
1962+
itemEncoding:
1963+
contentType: image/jpg
1964+
```
1965+
1966+
###### Example: Streaming Byte Ranges
1967+
1968+
For `multipart/byteranges` [[RFC9110]] [Section 14.6](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.6), a `Content-Range` header is required:
1969+
1970+
See [Appendix D](appendix-d-serializing-headers-and-cookies) for an explanation of why `content: {text/plain: {...}}` is used to describe the header value.
1971+
1972+
```yaml
1973+
multipart/byteranges:
1974+
itemSchema:
1975+
$comment: A single range of bytes from a video
1976+
itemEncoding:
1977+
contentType: video/mp4
1978+
headers:
1979+
Content-Range:
1980+
required: true
1981+
content:
1982+
text/plain:
1983+
schema:
1984+
# A suitable "pattern" constraint for this
1985+
# header is left as an exercise for the reader
1986+
type: string
1987+
```
1988+
18961989
###### Example: Nested `multipart/mixed`
18971990

18981991
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.
@@ -1901,7 +1994,6 @@ The nested parts are XML, plain text, and a PNG image.
19011994
```yaml
19021995
multipart/mixed:
19031996
schema:
1904-
type: array
19051997
prefixItems:
19061998
- type: array
19071999
- type: array

0 commit comments

Comments
 (0)