You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update "format" and "content*" for new JSON Schema (#2200)
* 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.
* "format" is an annotation
* Fix broken table, type, in Encoding Object
Broke some things while updating for "content*"
* Fix format of `format`
Backticks, not double quotes.
* Remove unneeded detail on "format"
This was just duplicating info from the JSON Schema spec.
Co-authored-by: Darrel <[email protected]>
* Remove "byte" and "binary" formats altogether.
Instead of just deprecating. The "content*" keywords now
cover these use cases.
* Harmonize JSON Schema content* + Media Type Object
Includes harmonizing with the Encoding Object. In general,
OpenAPI objects set the media type, although there is a case
for `contentMediaType` with multipart/form-data. Otherwise,
`contentEncoding` replaces the now-removed custom formats.
A possibly controversial change is to indicate unencoded binary
data by omitting `type` (or omitting the schema altogether), as
binary data does not conform to JSON string requirements.
This could still be done with `type: string` if that is preferred.
It's going to be a bit weird either way.
I can add wording in the next JSON Schema draft to clarify
whichever approach makes more sense.
* Fix typos from review
* Remove stray {}
* Fix inconsistencies contentMediaType and Encoding Object
Co-authored-by: Darrel <[email protected]>
Copy file name to clipboardExpand all lines: versions/3.1.0.md
+42-43Lines changed: 42 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -147,12 +147,14 @@ Primitive data types in the OAS are based on the types supported by the [JSON Sc
147
147
Note that `integer` as a type is also supported and is defined as a JSON number without a fraction or exponent part.
148
148
Models are defined using the [Schema Object](#schemaObject), which is a superset of JSON Schema Specification Draft 2019-09.
149
149
150
-
<aname="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
+
<aname="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.
152
152
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.
154
154
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.
155
155
156
+
Note that by default, JSON Schema validators will not attempt to validate the `format` keyword. https://json-schema.org/draft/2019-09/release-notes.html#format-vocabulary
@@ -161,15 +163,8 @@ The formats defined by the OAS are:
161
163
`integer` | `int64` | signed 64 bits (a.k.a long)
162
164
`number` | `float` | |
163
165
`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)
170
166
`string` | `password` | A hint to UIs to obscure input.
171
167
172
-
173
168
### <aname="richText"></a>Rich Text Formatting
174
169
Throughout the specification `description` fields are noted as supporting CommonMark markdown formatting.
175
170
Where OpenAPI tooling renders rich text it MUST support, at a minimum, markdown syntax as described by [CommonMark 0.27](https://spec.commonmark.org/0.27/). Tooling MAY choose to ignore some CommonMark features to address security concerns.
@@ -1447,20 +1442,35 @@ application/json:
1447
1442
1448
1443
##### Considerations for File Uploads
1449
1444
1450
-
In contrast with the 2.0 specification, `file` input/output content in OpenAPI is described with the same semantics as any other schema type. Specifically:
1445
+
In contrast with the 2.0 specification, `file` input/output content in OpenAPI is described with the same semantics as any other schema type. In contrast with the 3.0 specification, such schemas use the `contentEncoding` JSON Schema keyword rather than the `format` keyword. This keyword supports all encodings defined in [RFC4648](https://tools.ietf.org/html/rfc4648), including "base64" and "base64url", as well as "quoted-printable" from [RFC2045](https://tools.ietf.org/html/rfc2045#section-6.7).
1446
+
1447
+
JSON Schema also offers a `contentMediaType` keyword. However, when the media type is already specified by the
1448
+
Media Type Object's key, or by the `contentType` field of an [Encoding Object](#encodingObject), the `contentMediaType` keyword SHALL be ignored if present.
1449
+
1450
+
Examples:
1451
+
1452
+
Content transferred in binary (octet-stream) SHOULD omit `schema`, as no JSON Schema type is suitable:
1451
1453
1452
1454
```yaml
1453
-
# content transferred with base64 encoding
1454
-
schema:
1455
-
type: string
1456
-
format: base64
1455
+
# a PNG image as a binary file:
1456
+
content:
1457
+
image/png: {}
1457
1458
```
1458
1459
1459
1460
```yaml
1460
-
# content transferred in binary (octet-stream):
1461
-
schema:
1462
-
type: string
1463
-
format: binary
1461
+
# an arbitrary binary file:
1462
+
content:
1463
+
application/octet-stream: {}
1464
+
```
1465
+
1466
+
Binary content transferred with base64 encoding:
1467
+
1468
+
```yaml
1469
+
content:
1470
+
image/png:
1471
+
schema:
1472
+
type: string
1473
+
contentEncoding: base64
1464
1474
```
1465
1475
1466
1476
These examples apply to either input payloads of file uploads or response payloads.
@@ -1470,11 +1480,7 @@ A `requestBody` for submitting a file in a `POST` operation may look like the fo
1470
1480
```yaml
1471
1481
requestBody:
1472
1482
content:
1473
-
application/octet-stream:
1474
-
schema:
1475
-
# a binary file of any type
1476
-
type: string
1477
-
format: binary
1483
+
application/octet-stream: {}
1478
1484
```
1479
1485
1480
1486
In addition, specific media types MAY be specified:
@@ -1484,14 +1490,8 @@ In addition, specific media types MAY be specified:
1484
1490
requestBody:
1485
1491
content:
1486
1492
# a binary file of type png or jpeg
1487
-
'image/jpeg':
1488
-
schema:
1489
-
type: string
1490
-
format: binary
1491
-
'image/png':
1492
-
schema:
1493
-
type: string
1494
-
format: binary
1493
+
image/jpeg: {}
1494
+
image/png: {}
1495
1495
```
1496
1496
1497
1497
To upload multiple files, a `multipart` media type MUST be used:
@@ -1506,9 +1506,7 @@ requestBody:
1506
1506
file:
1507
1507
type: array
1508
1508
items:
1509
-
type: string
1510
-
format: binary
1511
-
1509
+
contentMediaType: application/octet-stream
1512
1510
```
1513
1511
1514
1512
##### Support for x-www-form-urlencoded Request Bodies
@@ -1546,8 +1544,10 @@ When passing in `multipart` types, boundaries MAY be used to separate sections o
1546
1544
1547
1545
* If the property is a primitive, or an array of primitive values, the default Content-Type is `text/plain`
1548
1546
* 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`
1547
+
* If the property is a `type: string` with a `contentEncoding`, the default Content-Type is `application/octet-stream`
1548
+
* If the JSON Schema keyword `contentMediaType` is used and no Encoding Object is present, then the Content-Type is that which is specified by `contentMediaType`, however if an Encoding Object is present, then `contentMediaType` SHALL be ignored
1550
1549
1550
+
As with non-multipart request or response bodies, when using `contentMediaType` to specify a binary Content-Type without also using `contentEncoding`, the JSON Schema `type` keyword is omitted.
1551
1551
1552
1552
Examples:
1553
1553
@@ -1566,9 +1566,8 @@ requestBody:
1566
1566
type: object
1567
1567
properties: {}
1568
1568
profileImage:
1569
-
# default Content-Type for string/binary is `application/octet-stream`
1570
-
type: string
1571
-
format: binary
1569
+
# Content-Type with contentMediaType is the contentMediaType (image/png here)
1570
+
contentMediaType: image/png
1572
1571
children:
1573
1572
# default Content-Type for arrays is based on the `inner` type (text/plain here)
1574
1573
type: array
@@ -1578,7 +1577,8 @@ requestBody:
1578
1577
# default Content-Type for arrays is based on the `inner` type (object shown, so `application/json` in this example)
1579
1578
type: array
1580
1579
items:
1581
-
type: '#/components/schemas/Address'
1580
+
type: object
1581
+
$ref: '#/components/schemas/Address'
1582
1582
```
1583
1583
1584
1584
An `encoding` attribute is introduced to give you control over the serialization of parts of `multipart` request bodies. This attribute is _only_ applicable to `multipart` and `application/x-www-form-urlencoded` request bodies.
@@ -1590,7 +1590,7 @@ A single encoding definition applied to a single schema property.
1590
1590
##### Fixed Fields
1591
1591
Field Name | Type | Description
1592
1592
---|:---:|---
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.
1593
+
<a name="encodingContentType"></a>contentType | `string` | The Content-Type for encoding a specific property. Default value depends on the property type: when `type` is absent and `contentMediaType` is present - the value of `contentMediaType`; when both `type` and `contentMediaType` are absent - `application/octet-stream`; for `string` with a `contentEncoding` - `application/octet-string`; 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.
1594
1594
<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`.
1595
1595
<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.
1596
1596
<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 +1621,8 @@ requestBody:
1621
1621
type: object
1622
1622
properties: {}
1623
1623
profileImage:
1624
-
# default is application/octet-stream, need to declare an image type only!
0 commit comments