Skip to content

Commit 318d43c

Browse files
committed
Update "format" and "content*" for new JSON Schema
This removes OAS formats and examples that are now superfluous as they are part of the 2019-09 JSON Schema draft. Similarly it deprecates the "byte" and "binary" formats in favor of JSON Schema's "contentEncoding" and "contentMediaType" keywords, and updates various related exapmles and other guidance. It also removes confusingly blank rows in the OAS format table.
1 parent 6abda3b commit 318d43c

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

versions/3.1.0.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ Primitive data types in the OAS are based on the types supported by the [JSON Sc
147147
Note that `integer` as a type is also supported and is defined as a JSON number without a fraction or exponent part.
148148
Models are defined using the [Schema Object](#schemaObject), which is a superset of JSON Schema Specification Draft 2019-09.
149149

150-
<a name="dataTypeFormat"></a>Primitives have an optional modifier property: `format`.
151-
OAS uses several known formats to define in fine detail the data type being used.
150+
<a name="dataTypeFormat"></a>Primitives have an optional modifier property: `format`, which is defined by JSON Schema.
151+
OAS uses several known additional formats to define in fine detail the data type being used.
152152
However, to support documentation needs, the `format` property is an open `string`-valued property, and can have any value.
153-
Formats such as `"email"`, `"uuid"`, and so on, MAY be used even though undefined by this specification.
153+
Additional formats MAY be used even though undefined by either JSON Schema or this specification.
154154
Types that are not accompanied by a `format` property follow the type definition in the JSON Schema. Tools that do not recognize a specific `format` MAY default back to the `type` alone, as if the `format` is not specified.
155155

156156
The formats defined by the OAS are:
@@ -161,14 +161,14 @@ The formats defined by the OAS are:
161161
`integer` | `int64` | signed 64 bits (a.k.a long)
162162
`number` | `float` | |
163163
`number` | `double` | |
164-
`string` | | |
165-
`string` | `byte` | base64 encoded characters
166-
`string` | `binary` | any sequence of octets
167-
`boolean` | | |
168-
`string` | `date` | As defined by `full-date` - [RFC3339](https://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)
169-
`string` | `date-time` | As defined by `date-time` - [RFC3339](https://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14)
170164
`string` | `password` | A hint to UIs to obscure input.
165+
`string` | `byte` | base64 encoded characters **Deprecated**
166+
`string` | `binary` | any sequence of octets **Deprecated**
171167

168+
Use of `byte` or `binary` is discouraged, and later versions of this specification may remove them from this list. They SHOULD be replaced with the JSON Schema keywords `contentEncoding` or `contentMediaType` as follows:
169+
170+
* replace `"format": "byte"` with `"contentEncoding": "base64"` or `"contentEncoding": "base64url"`
171+
* replace `"format": "binary"` with `"contentMediaType": "application/octet-stream"` or an appropriate specific media type
172172

173173
### <a name="richText"></a>Rich Text Formatting
174174
Throughout the specification `description` fields are noted as supporting CommonMark markdown formatting.
@@ -1453,14 +1453,14 @@ In contrast with the 2.0 specification, `file` input/output content in OpenAPI i
14531453
# content transferred with base64 encoding
14541454
schema:
14551455
type: string
1456-
format: base64
1456+
contentEncoding: base64
14571457
```
14581458

14591459
```yaml
14601460
# content transferred in binary (octet-stream):
14611461
schema:
14621462
type: string
1463-
format: binary
1463+
contentMediaType: application/octet-stream
14641464
```
14651465

14661466
These examples apply to either input payloads of file uploads or response payloads.
@@ -1474,7 +1474,7 @@ requestBody:
14741474
schema:
14751475
# a binary file of any type
14761476
type: string
1477-
format: binary
1477+
contentMediaType: application/octet-stream
14781478
```
14791479

14801480
In addition, specific media types MAY be specified:
@@ -1487,11 +1487,11 @@ requestBody:
14871487
'image/jpeg':
14881488
schema:
14891489
type: string
1490-
format: binary
1490+
contentMediaType: image/jpeg
14911491
'image/png':
14921492
schema:
14931493
type: string
1494-
format: binary
1494+
contentMediaType: image/png
14951495
```
14961496

14971497
To upload multiple files, a `multipart` media type MUST be used:
@@ -1507,7 +1507,7 @@ requestBody:
15071507
type: array
15081508
items:
15091509
type: string
1510-
format: binary
1510+
contentMediaType: application/octet-stream
15111511
15121512
```
15131513

@@ -1546,7 +1546,9 @@ When passing in `multipart` types, boundaries MAY be used to separate sections o
15461546

15471547
* If the property is a primitive, or an array of primitive values, the default Content-Type is `text/plain`
15481548
* If the property is complex, or an array of complex values, the default Content-Type is `application/json`
1549-
* If the property is a `type: string` with `format: binary` or `format: base64` (aka a file object), the default Content-Type is `application/octet-stream`
1549+
* If the property is a `type: string` with a `contentMediaType`, the Content-Type is the value from `contentMediaType`
1550+
* If the property is a `type: string` with a `contentEncoding` of `base64` or `base64url`, but does _not_ have a `contentMediaType`, the default Content-Type is `application/octet-stream`
1551+
* **Deprecated:** If the property is a `type: string` with `format: binary` or `format: base64` (aka a file object), the default Content-Type is `application/octet-stream`
15501552

15511553

15521554
Examples:
@@ -1566,9 +1568,9 @@ requestBody:
15661568
type: object
15671569
properties: {}
15681570
profileImage:
1569-
# default Content-Type for string/binary is `application/octet-stream`
1571+
# Content-Type for string/contentMediaType is the contentMediaType (image/png here)
15701572
type: string
1571-
format: binary
1573+
contentMediaType: image/png
15721574
children:
15731575
# default Content-Type for arrays is based on the `inner` type (text/plain here)
15741576
type: array
@@ -1590,7 +1592,13 @@ A single encoding definition applied to a single schema property.
15901592
##### Fixed Fields
15911593
Field Name | Type | Description
15921594
---|:---:|---
1593-
<a name="encodingContentType"></a>contentType | `string` | The Content-Type for encoding a specific property. Default value depends on the property type: for `string` with `format` being `binary` – `application/octet-stream`; for other primitive types – `text/plain`; for `object` - `application/json`; for `array` – the default is defined based on the inner type. The value can be a specific media type (e.g. `application/json`), a wildcard media type (e.g. `image/*`), or a comma-separated list of the two types.
1595+
<a name="encodingContentType"></a>contentType | `string` | The Content-Type for encoding a specific property. Default value depends on the property type:
1596+
1597+
* for `type` with a `contentMediaType`, the default value is the value from `contentMediaType`
1598+
* for other primitive types – `text/plain`; for `object` - `application/json`
1599+
* for `array` – the default is defined based on the inner type. The value can be a specific media type (e.g. `application/json`), a wildcard media type (e.g. `image/*`), or a comma-separated list of the two types
1600+
* **Deprecated:** for `string` with `format` being `binary` – `application/octet-stream`
1601+
15941602
<a name="encodingHeaders"></a>headers | Map[`string`, [Header Object](#headerObject) \| [Reference Object](#referenceObject)] | A map allowing additional information to be provided as headers, for example `Content-Disposition`. `Content-Type` is described separately and SHALL be ignored in this section. This property SHALL be ignored if the request body media type is not a `multipart`.
15951603
<a name="encodingStyle"></a>style | `string` | Describes how a specific property value will be serialized depending on its type. See [Parameter Object](#parameterObject) for details on the [`style`](#parameterStyle) property. The behavior follows the same values as `query` parameters, including default values. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of [`contentType`](#encodingContentType) (implicit or explicit) SHALL be ignored.
15961604
<a name="encodingExplode"></a>explode | `boolean` | When this is true, property values of type `array` or `object` generate separate parameters for each value of the array, or key-value-pair of the map. For other types of properties this property has no effect. When [`style`](#encodingStyle) is `form`, the default value is `true`. For all other styles, the default value is `false`. This property SHALL be ignored if the request body media type is not `application/x-www-form-urlencoded` or `multipart/form-data`. If a value is explicitly defined, then the value of [`contentType`](#encodingContentType) (implicit or explicit) SHALL be ignored.
@@ -1621,9 +1629,8 @@ requestBody:
16211629
type: object
16221630
properties: {}
16231631
profileImage:
1624-
# default is application/octet-stream, need to declare an image type only!
16251632
type: string
1626-
format: binary
1633+
contentMediaType: image/jpeg
16271634
encoding:
16281635
historyMetadata:
16291636
# require XML Content-Type in utf-8 encoding

0 commit comments

Comments
 (0)