Skip to content

Commit fc2a9d7

Browse files
handrewsjdesrosiers
andcommitted
Further clarify discriminator usage (3.0.4)
This backports changes made to the Discriminator Object in 3.1.1 and merges them with the changes made on this branch. Note that the previouc changes incorporated reworked ideas from @jdesrosiers regarding the ambiguous `mapping` syntax submitted in the 3.1.1 changes but not accepted at that time due to compatibility concerns. This commit merges in the parts of that 3.1.1 change that were accepted. For the same compatibility reasons, the MUST wording for requiring the named discriminator property in the schema was (regrettably) weakened to a "SHOULD but otherwise undefined", as we have done for other problematic ambiguities. Co-authored-by: Jason Desrosiers <[email protected]>
1 parent 87d023a commit fc2a9d7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

versions/3.0.4.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ When parsing an OAD, JSON or YAML objects are parsed into specific Objects (such
163163

164164
If the same JSON/YAML object is parsed multiple times and the respective contexts require it to be parsed as _different_ Object types, the resulting behavior is _implementation defined_, and MAY be treated as an error if detected. An example would be referencing an empty Schema Object under `#/components/schemas` where a Path Item Object is expected, as an empty object is valid for both types. For maximum interoperability, it is RECOMMENDED that OpenAPI Description authors avoid such scenarios.
165165

166+
#### <a name="resolvingImplicitConnections"></a>Resolving Implicit Connections
167+
168+
***TODO: In another PR***
169+
166170
### <a name="dataTypes"></a>Data Types
167171

168172
Primitive data types in the OAS are based on the types supported by the [JSON Schema Specification Wright Draft 00](https://tools.ietf.org/html/draft-wright-json-schema-00#section-4.2).
@@ -2747,12 +2751,14 @@ components:
27472751
27482752
#### <a name="discriminatorObject"></a>Discriminator Object
27492753
2750-
When request bodies or response payloads may be one of a number of different schemas, a Discriminator Object can be used to aid in serialization, deserialization, and validation by implicitly or explicitly associating the possible values of a named property with alternative schemas.
2754+
When request bodies or response payloads may be one of a number of different schemas, a Discriminator Object gives a hint about the expected schema of the document.
2755+
This hint can be used to aid in serialization, deserialization, and validation.
2756+
The Discriminator Object does this by implicitly or explicitly associating the possible values of a named property with alternative schemas.
27512757
27522758
##### Fixed Fields
27532759
Field Name | Type | Description
27542760
---|:---:|---
2755-
<a name="propertyName"></a>propertyName | `string` | **REQUIRED**. The name of the property in the payload that will hold the discriminator value.
2761+
<a name="propertyName"></a>propertyName | `string` | **REQUIRED**. The name of the property in the payload that will hold the discriminator value. This property SHOULD be required in the payload schema, as the behavior when the property is absent is undefined.
27562762
<a name="discriminatorMapping"></a> mapping | Map[`string`, `string`] | An object to hold mappings between payload values and schema names or URI references.
27572763

27582764
##### Conditions for Using the Discriminator Object
@@ -2776,6 +2782,10 @@ However, the exact nature of such conversions are implementation-defined.
27762782

27772783
##### <a name="discriminatorExamples"></a>Examples
27782784

2785+
For these examples, assume all schemas are in the entry OpenAPI document; for handling of `discriminator` in referenced documents see [Resolving Implicit Connections](#resolvingImplicitConnections).
2786+
2787+
##### <a name="discriminatorExamples"></a>Examples
2788+
27792789
In OAS 3.0, a response payload MAY be described to be exactly one of any number of types:
27802790

27812791
```yaml
@@ -2826,7 +2836,7 @@ MyResponseType:
28262836
monster: https://gigantic-server.com/schemas/Monster/schema.json
28272837
```
28282838

2829-
Here the discriminator _value_ of `dog` will map to the schema `#/components/schemas/Dog`, rather than the default (implicit) value of `Dog`. If the discriminator _value_ does not match an implicit or explicit mapping, no schema can be determined and validation SHOULD fail.
2839+
Here the discriminator property _value_ of `dog` will map to the schema `#/components/schemas/Dog`, rather than the default (implicit) value of `#/components/schemas/dog`. If the discriminator property _value_ does not match an implicit or explicit mapping, no schema can be determined and validation SHOULD fail.
28302840

28312841
When used in conjunction with the `anyOf` construct, the use of the discriminator can avoid ambiguity where multiple schemas may satisfy a single payload.
28322842

0 commit comments

Comments
 (0)