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
Copy file name to clipboardExpand all lines: src/oas.md
+46-1Lines changed: 46 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1319,6 +1319,51 @@ properties:
1319
1319
The three encoding fields define how to map each [Encoding Object](#encoding object) to a specific value in the data.
1320
1320
Each field has its own set of media types with which it can be used; for all other media types all three fields SHALL be ignored.
1321
1321
1322
+
###### Encoding and `type`
1323
+
1324
+
Several encoding behaviors, including which of the Media Type Object's encoding fields can be used, the way in which those fields apply Encoding Objects to either the immediate instance or to items in an instance array, and the default behavior of the Encoding Object's `contentType` field, depend on the relevant schema's `type`.
1325
+
1326
+
When only a single Schema Object with a single-valued `type` keyword is relevant, this behavior is easily-determined.
1327
+
However, when schemas are assembled through references, this can be more challenging.
1328
+
When schemas have constraints that are only resolvable at runtime, determining the type prior to runtime can be impossible.
1329
+
1330
+
When working with in-memory data at runtime, if an implementation cannot locate an appropriate `type` keyword but the data is valid according to all relevant Schema Objects, then the runtime type of the data MUST be used to determine the behavior.
1331
+
1332
+
When parsing a data format using an Encoding Object, implementations MUST support using a single-valued `type` keyword that is either in the corresponding Schema Object, or reachable from that Schema Object by following a chain of `$ref` and/or `allOf` keywords.
1333
+
Note that if `allOf` is used to combine single-valued `type` keywords with conflicting type values, schema validation will always fail, so such conflicts need not be detected in advance as long as validation is applied to the parsed result.
1334
+
Note also that while the `type` value `"integer"` can be applied with `type: "number"`, the encoding behavior is the same for JSON numbers whether they meet JSON Schema's additional `type: "integer"` constraint or not, so these types do not conflict.
1335
+
1336
+
For example, the relevant type of the `"foo"` property is `"number"`, found by following the `$ref` to the `"Thing"` schema, then the `$ref` under the `"foo"` property schema to the `"Foo"` schema, then the `$ref` under the first branch of the `allOf` to the `"Bar"` schema, which defines a `type` keyword with the single value `"number"`, a primitive type:
1337
+
1338
+
```yaml
1339
+
components:
1340
+
schemas:
1341
+
Thing:
1342
+
type: object
1343
+
properties:
1344
+
foo:
1345
+
$ref: "#/components/Schemas/Foo"
1346
+
Foo:
1347
+
allOf:
1348
+
- $ref: "#/components/Schemas/Bar"
1349
+
- $ref: "#/components/Schemas/Baz"
1350
+
Bar:
1351
+
type: number
1352
+
Baz:
1353
+
minimum: 0
1354
+
requestBodies:
1355
+
Thing:
1356
+
schema:
1357
+
$ref: "#/components/Schemas/Thing"
1358
+
encoding:
1359
+
foo:
1360
+
# The default `contentType` is `text/plain`
1361
+
```
1362
+
1363
+
Implementations MAY attempt to handle more complex schema arrangements, in which case they MUST document what is handled and with what behavior.
1364
+
If they do, then `type` keywords that contain multiple values (e.g. `type: ["number", "nul"]`) SHOULD be handled by attempting to parse according to each type in the order provided, falling back to the next type until the list is exhausted.
1365
+
However OAD authors are advised that depending on handling scenarios other than `$ref`/`allOf`-reachable single-valued `type` keywords is not interoperable.
1366
+
1322
1367
###### Encoding By Name
1323
1368
1324
1369
The behavior of the `encoding` field is designed to support web forms, and is therefore only defined for media types structured as name-value pairs that allow repeat values, most notably `application/x-www-form-urlencoded` and `multipart/form-data`.
@@ -1669,7 +1714,7 @@ These fields MAY be used either with or without the RFC6570-style serialization
1669
1714
This object MAY be extended with [Specification Extensions](#specification-extensions).
1670
1715
1671
1716
The default values for `contentType` are as follows, where an _n/a_ in the `contentEncoding` column means that the presence or value of `contentEncoding` is irrelevant.
1672
-
This table is based on the value to which the Encoding Object is being applied as defined under [Encoding Usage and Restrictions](#encoding-usage-and-restrictions).
1717
+
This table is based on the value to which the Encoding Object is being applied as defined under [Encoding Usage and Restrictions](#encoding-usage-and-restrictions), where determining the type is done as described under [Encoding and `type`](#encoding-and-type).
1673
1718
Note that in the case of [Encoding By Name](#encoding-by-name), this value is the array item for properties of type `"array"`, and the entire value for all other types.
1674
1719
Therefore the `array` row in this table applies only to array values inside of a top-level array when encoding by name.
0 commit comments