Skip to content

Commit 1ca6697

Browse files
authored
Merge pull request #3907 from handrews/disc-val-304
Clarify discriminator non-impact on validation
2 parents 11fc80e + 7b3d9d9 commit 1ca6697

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
@@ -3062,6 +3062,8 @@ When request bodies or response payloads may be one of a number of different sch
30623062
This hint can be used to aid in serialization, deserialization, and validation.
30633063
The Discriminator Object does this by implicitly or explicitly associating the possible values of a named property with alternative schemas.
30643064
3065+
Note that `discriminator` MUST NOT change the validation outcome of the schema.
3066+
30653067
##### Fixed Fields
30663068
Field Name | Type | Description
30673069
---|:---:|---
@@ -3070,11 +3072,16 @@ Field Name | Type | Description
30703072

30713073
##### Conditions for Using the Discriminator Object
30723074
The Discriminator Object is legal only when using one of the composite keywords `oneOf`, `anyOf`, `allOf`.
3075+
30733076
In both the `oneOf` and `anyOf` use cases, where those keywords are adjacent to `discriminator`, all possible schemas MUST be listed explicitly.
3077+
30743078
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.
30753079
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.
30763080
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.
30773081

3082+
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.
3083+
This is because `discriminator` cannot change the validation outcome, and no standard JSON Schema keyword connects the parent schema to the child schemas.
3084+
30783085
The behavior of any configuration of `oneOf`, `anyOf`, `allOf` and `discriminator` that is not described above is undefined.
30793086

30803087
##### Options for Mapping Values to Schemas

0 commit comments

Comments
 (0)