Skip to content

Commit 7b3d9d9

Browse files
committed
Clarify discriminator non-impact on validation
Be very explicit that discriminator MUST NOT change the validation outcome, and explain the implication for the "allOf" use case.
1 parent eec1906 commit 7b3d9d9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

versions/3.0.4.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,6 +3026,8 @@ When request bodies or response payloads may be one of a number of different sch
30263026
This hint can be used to aid in serialization, deserialization, and validation.
30273027
The Discriminator Object does this by implicitly or explicitly associating the possible values of a named property with alternative schemas.
30283028
3029+
Note that `discriminator` MUST NOT change the validation outcome of the schema.
3030+
30293031
##### Fixed Fields
30303032
Field Name | Type | Description
30313033
---|:---:|---
@@ -3034,11 +3036,16 @@ Field Name | Type | Description
30343036

30353037
##### Conditions for Using the Discriminator Object
30363038
The Discriminator Object is legal only when using one of the composite keywords `oneOf`, `anyOf`, `allOf`.
3039+
30373040
In both the `oneOf` and `anyOf` use cases, where those keywords are adjacent to `discriminator`, all possible schemas MUST be listed explicitly.
3041+
30383042
To avoid redundancy, the discriminator MAY be added to a parent schema definition, and all schemas building on the parent schema via an `allOf` construct may be used as an alternate schema.
30393043
It is implementation-defined as to whether all named [Schema Objects](#schemaObject) under the [Components Object](#componentsObject), or only those that are otherwise directly referenced are searched for `allOf` references to the parent schema.
30403044
However, it is RECOMMENDED to search all named schemas in the Components Object because it is common with the `allOf` usage for other parts of the API to only directly reference the parent schema.
30413045

3046+
The `allOf` form of `discriminator` is _only_ useful for non-validation use cases; validation with the parent schema with this form of `discriminator` _does not_ perform a search for child schemas or use them in validation in any way.
3047+
This is because `discriminator` cannot change the validation outcome, and no standard JSON Schema keyword connects the parent schema to the child schemas.
3048+
30423049
The behavior of any configuration of `oneOf`, `anyOf`, `allOf` and `discriminator` that is not described above is undefined.
30433050

30443051
##### Options for Mapping Values to Schemas

0 commit comments

Comments
 (0)