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
+6-7Lines changed: 6 additions & 7 deletions
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` keyword.
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.
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. The discriminator is a specific object in a schema which is used to inform the consumer of the document of an alternative schema based on the value associated with it.
2697
+
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. The `discriminator` keyword is used to inform the consumer of the document which of the alternatives is expected or preferred.
2698
2698
2699
2699
`discriminator`uses a schema's "name" to automatically map a property value to
2700
2700
a schema. The schema's "name" is the property name used when declaring the
@@ -2722,8 +2722,7 @@ MyResponseType:
2722
2722
- $ref: '#/components/schemas/Lizard'
2723
2723
```
2724
2724
2725
-
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:
2726
-
2725
+
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:
2727
2726
2728
2727
```yaml
2729
2728
MyResponseType:
@@ -2744,7 +2743,7 @@ The expectation now is that a property with name `petType` _MUST_ be present in
2744
2743
}
2745
2744
```
2746
2745
2747
-
Will indicate that the `Cat` schema be used in conjunction with this payload.
2746
+
Will indicate that the `Cat` schema is the alternative that is expected to match this payload.
2748
2747
2749
2748
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:
2750
2749
@@ -2764,7 +2763,7 @@ MyResponseType:
2764
2763
2765
2764
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.
2766
2765
2767
-
When used in conjunction with the `anyOf` construct, the use of the discriminator can avoid ambiguity where multiple schemas may satisfy a single payload.
2766
+
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.
2768
2767
2769
2768
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.
2770
2769
@@ -2819,7 +2818,7 @@ a payload like this:
2819
2818
}
2820
2819
```
2821
2820
2822
-
will indicate that the `#/components/schemas/Cat` schema be used. Likewise this payload:
2821
+
will indicate that the `#/components/schemas/Cat` schema is expected to match. Likewise this payload:
0 commit comments