Skip to content

Commit cfc9d18

Browse files
committed
Media Types Registry
This registry groups media types by their data modeling approaches, and provides pages that give a brief overview of that approach as well as links to relevant OAS sections. The section titles and anchors are intended to work with 3.2 (so we should not publish it until 3.2 is published). The summary and remarks are only intended to give the general idea of how the media types work, and what changes have been made from release to release. This initial set only includes media types that are mentioned in the OAS, but the layout should work without needing any links to such sections. We'll have to decide how much detail to put if and when we start making additions outside of the OAS, which we hope to eventually do. The point of this is to not require a minor OAS version to add future media types, as long as they do not require new fields or Objects. I omitted YAML since AFAIK it is rarely used in actual API payloads, and the OAS provides no guidance on how to handle YAML features that are not compatible with JSON. And of course for JSON-compatible YAML, you just treat it like JSON.
1 parent d626b79 commit cfc9d18

File tree

11 files changed

+309
-0
lines changed

11 files changed

+309
-0
lines changed

_config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ collections:
1818
name: Format Registry
1919
output: true
2020
permalink: /registry/:collection/:title
21+
media-type:
22+
slug: media-type
23+
name: Media Type Registry
24+
output: true
25+
permalink: /registry/:collection/:title
2126
extension:
2227
slug: extension
2328
name: Specification Extension Registry

_includes/media-type-entry.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# <a href=".">{{ page.collection }}</a>
2+
3+
## {{ page.description }}
4+
5+
**Media Type(s):**
6+
7+
{% for media_type in page.media_types %}• <tt>{{ media_type.name }}</tt>{% unless media_type.registered %} _<small>(not IANA-registered)</small>_{% endunless %}{% unless forloop.last %}<br />{% endunless %}{% endfor %}
8+
{% if page.default_for %}
9+
10+
This page also applies to any unknown {{ page.default_for }} media type.
11+
{% endif %}
12+
13+
{% if page.references %}
14+
**OAS References:**
15+
16+
{% for ref in page.references %}• [{{ ref.section }}](https://spec.openapis.org/oas/latest.html#{{ ref.anchor }})<br />{% endfor %}
17+
{% endif %}
18+
19+
## Summary
20+
21+
{{ include.summary }}
22+
23+
{% if include.remarks %}
24+
## Remarks
25+
26+
{{ include.remarks }}
27+
{% endif %}
28+

registries/_media-type/binary.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
owner: handrews
3+
description: Binary
4+
media_types:
5+
- name: application/octet-stream
6+
registered: true
7+
- name: audio/*
8+
registered: true
9+
- name: image/*
10+
registered: true
11+
- name: video/*
12+
registered: true
13+
default_for: binary
14+
references:
15+
- section: Working with Binary Data
16+
anchor: working-with-binary-data
17+
- section: Binary Streams
18+
anchor: binary-streams
19+
layout: default
20+
---
21+
22+
{% capture summary %}
23+
As of OAS v3.1, binary data is modeled using an empty Schema Object, in accordance with JSON Schema's guidance regarding [non-JSON instances](https://www.ietf.org/archive/id/draft-bhutton-json-schema-01.html#name-non-json-instances).
24+
{% endcapture %}
25+
26+
{% capture remarks %}
27+
As specified in the linked reference section ("Working with Binary Data"), modeling binary data that has been encoded into a string is handled differently from raw binary data, with two variations: With an Encoding Object or with the Schema Object's `contentMediaType` and `contentEncoding`.
28+
29+
In OAS v3.0, raw binary content was modeled as `type: string, format: binary`, while `type: string, format: byte` was used for base64-encoded binary. This was dropped in favor of JSON Schema draft 2020-12's support because it did not allow specifying the media type along with the binary encoding.
30+
{% endcapture %}
31+
32+
{% include media-type-entry.md summary=summary remarks=remarks %}

registries/_media-type/forms.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
owner: handrews
3+
description: Forms
4+
media_types:
5+
- name: application/x-www-form-urlencoded
6+
registered: true
7+
- name: multipart/form-data
8+
registered: true
9+
references:
10+
- section: Encoding the x-www-form-urlencoded Media Type
11+
anchor: encoding-the-x-www-form-urlencoded-media-type
12+
- section: Encoding By Name
13+
anchor: encoding-by-name
14+
- section: Encoding multipart Media Types
15+
anchor: encoding-multipart-media-types
16+
- section: "Appendix C: Using RFC6570-Based Serialization"
17+
anchor: appendix-c-using-rfc6570-based-serialization
18+
- section: "Appendix E: Percent-Encoding and Form Media Types"
19+
anchor: appendix-e-percent-encoding-and-form-media-types
20+
layout: default
21+
---
22+
23+
{% capture summary %}
24+
Web-style form data consists of name-value pairs, with duplicate names allowed, and are structured either in a way compatible with URI form query strings or as a `multipart` document.
25+
{% endcapture %}
26+
27+
{% capture remarks %}
28+
Both form media types use the Encoding Object to map object properties from schema-ready data structures to name-value pairs, with special rules for arrays causing each array value to be treated as a separate pair with the same name.
29+
While the ordering of pairs is significant in these formats, the OAS does not (as of v3.2) provide a way to control such ordering.
30+
31+
As of OAS v3.2, endpoint URL query strings can be modeled as a media type using `in: querystring` in the Parameter Object. The query string can also be modeled using multiple `in: query` Parameter Objects through mechanisms similar to the Encoding Object.
32+
{% endcapture %}
33+
34+
{% include media-type-entry.md summary=summary remarks=remarks %}

registries/_media-type/linksets.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
owner: handrews
3+
description: Link Sets
4+
media_types:
5+
- name: application/linkset
6+
registered: true
7+
- name: application/linkset+json
8+
registered: true
9+
references:
10+
- section: Modeling Link Headers
11+
anchor: modeling-link-headers
12+
layout: default
13+
---
14+
15+
{% capture summary %}
16+
The JSON form for linksets is used to define the schema-ready data form for modeling the HTTP `Link` header, with the rules for converting from that form to `application/linkset` and then to the single-line HTTP field syntax defining the serialization process for that data.
17+
{% endcapture %}
18+
19+
{% capture remarks %}
20+
In addition to modeling the `Link` header, these two media types are supported anywhere else a media type document is allowed.
21+
In all cases, the `application/linkset+json` data model is used with the Schema Object, with the choice of the parent key for the Media Type Object (with or without `+json`) determining only the serialization.
22+
{% endcapture %}
23+
24+
{% include media-type-entry.md summary=summary remarks=remarks %}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
owner: handrews
3+
description: Sequential JSON
4+
media_types:
5+
- name: application/jsonl
6+
registered: false
7+
- name: application/x-ndjson
8+
registered: false
9+
- name: application/json-seq
10+
registered: true
11+
references:
12+
- section: Sequential Media Types
13+
anchor: sequential-media-types
14+
- section: Streaming Sequential Media Types
15+
anchor: streaming-sequential-media-types
16+
- section: Sequential JSON (examples)
17+
anchor: sequential-json
18+
layout: default
19+
---
20+
21+
{% capture summary %}
22+
Sequential JSON media types concatenate multiple JSON documents into one document or stream, and only vary in their choices of delimiter and the restrictions on what whitespace is allowed between JSON syntax tokens.
23+
{% endcapture %}
24+
25+
{% capture remarks %}
26+
All sequential JSON media types support the same two approaches:
27+
* Use the `schema` field to model the whole document as if it were a JSON array
28+
* Use `itemSchema` to model one item at a time for streaming purposes, where all items use the same schema
29+
{% endcapture %}
30+
31+
{% include media-type-entry.md summary=summary remarks=remarks %}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
owner: handrews
3+
description: Sequential Multipart
4+
media_types:
5+
- name: multipart/*
6+
registered: true
7+
- name: multipart/mixed
8+
registered: true
9+
- name: multipart/alternative
10+
registered: true
11+
- name: multipart/related
12+
registered: true
13+
- name: multipart/byteranges
14+
registered: true
15+
references:
16+
- section: Encoding By Position
17+
anchor: encoding-by-position
18+
- section: Encoding multipart Media Types
19+
anchor: encoding-multipart-media-types
20+
layout: default
21+
---
22+
23+
{% capture summary %}
24+
All `multipart` media types are based on a common syntax defined by `multipart/mixed`, and any `multipart` subtype not explicitly registered is expected to be usable by treating it as `multipart/mixed` in accordance with [RFC2046 §5.1.3](https://www.rfc-editor.org/rfc/rfc2046.html#section-5.1.3).
25+
{% endcapture %}
26+
27+
{% capture remarks %}
28+
All known `multipart` subtypes except `multipart/form-data` are ordered, without any names for the parts.
29+
They are either modeled as arrays using `schema`, or a uniform schema can be applied to each part for streaming purposes using `itemSchema` (this is particularly relevant to `multipart/byteranges`).
30+
In both cases, `itemEncoding` can used to manage the media type and headers of each, while if `schema` is used, `prefixEncoding` is also available for describing some fixed number of initial parts in a specific order.
31+
32+
The `boundary` required parameter is common to all `multipart` subtypes, but does not need to be described explicitly in OpenAPI Descriptions as it is typically generated and used automatically, with a value that is not predictable in advance.
33+
34+
Note that OAS v3.0 claimed support for `multipart/mixed`, but did not define a mechanism for doing so for reasons that are no longer known. This claim of support was removed in OAS v3.0.4 and OAS v3.1.1, but can be seen in older patch releases of the 3.0 and 3.1 lines.
35+
{% endcapture %}
36+
37+
{% include media-type-entry.md summary=summary remarks=remarks %}
38+

registries/_media-type/sse.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
owner: handrews
3+
description: Server-Sent Events
4+
media_types:
5+
- name: text/event-stream
6+
registered: false
7+
references:
8+
- section: Sequential Media Types
9+
anchor: sequential-media-types
10+
- section: Special Considerations for `text/event-stream` Content
11+
anchor: special-considerations-for-text-event-stream-conten
12+
- section: Server-Sent Event Streams (example)
13+
anchor: server-sent-event-streams
14+
layout: default
15+
---
16+
17+
{% capture summary %}
18+
Server-Sent Events use the `text/event-stream` media type to stream events.
19+
Each event is modeled as if it were a JSON object with fields and types
20+
as given in the SSE specification, ignoring comments (fields with an empty string for the name) and any variations in serialization that represent the same event content.
21+
{% endcapture %}
22+
23+
{% capture remarks %}
24+
A complete event stream can be modeled as if it were a JSON array of such objects in the `schema` field, but the more common use case is to use the `itemSchema` field to apply the same schema to each event as it is streamed.
25+
26+
Note that application-level conventions regarding event usage (e.g. "sentinel events") that are not part of the media type specification are not modeled, as the OAS does not currently (as of OAS v3.2) work with semantics above the media type level.
27+
{% endcapture %}
28+
29+
{% include media-type-entry.md summary=summary remarks=remarks %}

registries/_media-type/text.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
owner: handrews
3+
description: Text
4+
media_types:
5+
- name: text/*
6+
registered: true
7+
- name: text/plain
8+
registered: true
9+
default_for: text-based (not just <tt>text/*</tt>)
10+
references:
11+
- section: Parameter Object
12+
anchor: parameter-object
13+
- section: Header Object
14+
anchor: header-object
15+
- section: Encoding Object
16+
anchor: encoding-object
17+
- section: "Appendix D: Serializing Headers and Cookies"
18+
anchor: appendix-d-serializing-headers-and-cookies
19+
layout: default
20+
---
21+
22+
{% capture summary %}
23+
A plain text document is modeled as a single string.
24+
{% endcapture %}
25+
26+
{% capture remarks %}
27+
In addition to normal use as HTTP message contents or `multipart` parts, `text/plain` is useful with the `content` field of the Parameter Object or Header Object to work around the automatic percent-encoding triggered by the use of the `schema` field.
28+
In particular, cookies with multiple values are not well-served by `style: form` and are better modeled as text.
29+
30+
Note that unlike JSON strings, the contents of the string representing the plain text are not quoted when serializing to a document. While a Schema Object of `{type: string, const: foo}` for JSON validates the JSON value `"foo"`, for plain text it validates `foo`, without quotes.
31+
{% endcapture %}
32+
33+
{% include media-type-entry.md summary=summary remarks=remarks %}

registries/_media-type/xml.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
owner: handrews
3+
description: XML
4+
media_types:
5+
- name: application/xml
6+
registered: true
7+
references:
8+
- section: XML Object
9+
anchor: xml-object
10+
- section: XML Modeling
11+
anchor: xml-modeling
12+
layout: default
13+
---
14+
15+
{% capture summary %}
16+
XML is modeled using the OAS's `xml` extension keyword for JSON Schema, which has an XML Object as its value.
17+
{% endcapture %}
18+
19+
{% capture remarks %}
20+
As of OAS v3.2, the XML Object uses the `nodeType` field to determine the type of [interface node](https://dom.spec.whatwg.org/#interface-node) to which a given Schema Object corresponds: `element`, `attribute`, `text`, `cdata`, or `none`. If `nodeType` is set to `none`, a Schema Object does not correspond to anything and the nodes corresponding to its immediate subschemas are placed directly under the node of its parent schema.
21+
22+
Certain behaviors are retained for compatibility with OAS v3.1, including implicit text nodes for elements with a primitive type, and somewhat complex rules for the default value of `nodeType`.
23+
In OAS v3.1 and earlier, only elements, their implicit primitive-type text nodes, and attributes were supported, with the now-deprecated `attribute` and `wrapped` flags as controls.
24+
{% endcapture %}
25+
26+
{% include media-type-entry.md summary=summary remarks=remarks %}

0 commit comments

Comments
 (0)