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
The `discriminator` keyword can't be a hint and a shortcut. I tried here
to modify any language that might suggest that `discriminator` overrides
the behavior of `anyOf`/`oneOf` in any way.
Copy file name to clipboardExpand all lines: versions/3.1.1.md
+5-6
Original file line number
Diff line number
Diff line change
@@ -2347,7 +2347,7 @@ The OpenAPI Specification allows combining and extending model definitions using
2347
2347
2348
2348
While composition offers model extensibility, it does not imply a hierarchy between the models.
2349
2349
To support polymorphism, the OpenAPI Specification adds the `discriminator` field.
2350
-
When used, the `discriminator` will indicate the name of the property that decides which schema definition validates the structure of the model.
2350
+
When used, the `discriminator` will indicate the name of the property that hints which schema definition is expected to validate the structure of the model.
2351
2351
As such, that property MUST be a required field.
2352
2352
There are two ways to define the value of a discriminator for an inheriting instance.
2353
2353
- Use the schema name.
@@ -2727,8 +2727,7 @@ MyResponseType:
2727
2727
- $ref: '#/components/schemas/Lizard'
2728
2728
```
2729
2729
2730
-
which means the payload _MUST_, by validation, match exactly one of the schemas described by `Cat`, `Dog`, or `Lizard`. In this case, a discriminator MAY act as a "hint" to shortcut validation and selection of the matching schema which may be a costly operation, depending on the complexity of the schema. We can then describe exactly which field tells us which schema to use:
2731
-
2730
+
which means the payload _MUST_, by validation, match exactly one of the schemas described by `Cat`, `Dog`, or `Lizard`. Evaluating a `oneOf` can be a costly operation, so `discriminator` MAY be used as a "hint" to improve the efficiency of validation and selection of the matching schema. The `discriminator` keyword can not change the validation result of the `oneOf`, it can only help make the evaluation more efficient and provide better error messaging. We can then describe exactly which field tells us which schema is expected to match the instance:
2732
2731
2733
2732
```yaml
2734
2733
MyResponseType:
@@ -2749,7 +2748,7 @@ The expectation now is that a property with name `petType` _MUST_ be present in
2749
2748
}
2750
2749
```
2751
2750
2752
-
Will indicate that the `Cat` schema be used in conjunction with this payload.
2751
+
Will indicate that the `Cat` schema is the alternative that is expected to match this payload.
2753
2752
2754
2753
In scenarios where the value of the discriminator field does not match the schema name or implicit mapping is not possible, an optional `mapping` definition MAY be used:
2755
2754
@@ -2769,7 +2768,7 @@ MyResponseType:
2769
2768
2770
2769
Here the discriminator _value_ of `dog` will map to the schema `#/components/schemas/Dog`, rather than the default (implicit) `#/components/schemas/dog`. If the discriminator _value_ does not match an implicit or explicit mapping, no schema can be determined and validation SHOULD fail. Mapping keys MUST be string values, but tooling MAY convert response values to strings for comparison.
2771
2770
2772
-
When used in conjunction with the `anyOf` construct, the use of the discriminator can avoid ambiguity where multiple schemas may satisfy a single payload.
2771
+
When used in conjunction with the `anyOf` construct, the use of the discriminator can avoid ambiguity for serializers/deserializers where multiple schemas may satisfy a single payload.
2773
2772
2774
2773
In both the `oneOf` and `anyOf` use cases, all possible schemas MUST be listed explicitly. To avoid redundancy, the discriminator MAY be added to a parent schema definition, and all schemas comprising the parent schema in an `allOf` construct may be used as an alternate schema.
2775
2774
@@ -2824,7 +2823,7 @@ a payload like this:
2824
2823
}
2825
2824
```
2826
2825
2827
-
will indicate that the `#/components/schemas/Cat` schema be used. Likewise this payload:
2826
+
will indicate that the `#/components/schemas/Cat` schema is expected to match. Likewise this payload:
0 commit comments