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
Data types in the OAS are based on the types supported by the [JSON Schema Specification Draft 2020-12](https://tools.ietf.org/html/draft-bhutton-json-schema-00#section-4.2.1).
@@ -2671,7 +2673,7 @@ components:
2671
2673
]
2672
2674
},
2673
2675
"Cat": {
2674
-
"description": "A representation of a cat. Note that `Cat` will be used as the discriminator value.",
2676
+
"description": "A representation of a cat. Note that `Cat` will be used as the discriminating value.",
2675
2677
"allOf": [
2676
2678
{
2677
2679
"$ref": "#/components/schemas/Pet"
@@ -2698,7 +2700,7 @@ components:
2698
2700
]
2699
2701
},
2700
2702
"Dog": {
2701
-
"description": "A representation of a dog. Note that `Dog` will be used as the discriminator value.",
2703
+
"description": "A representation of a dog. Note that `Dog` will be used as the discriminating value.",
2702
2704
"allOf": [
2703
2705
{
2704
2706
"$ref": "#/components/schemas/Pet"
@@ -2740,7 +2742,7 @@ components:
2740
2742
required:
2741
2743
- name
2742
2744
- petType
2743
-
Cat: # "Cat" will be used as the discriminator value
2745
+
Cat: # "Cat" will be used as the discriminating value
2744
2746
description: A representation of a cat
2745
2747
allOf:
2746
2748
- $ref: '#/components/schemas/Pet'
@@ -2756,7 +2758,7 @@ components:
2756
2758
- aggressive
2757
2759
required:
2758
2760
- huntingSkill
2759
-
Dog: # "Dog" will be used as the discriminator value
2761
+
Dog: # "Dog" will be used as the discriminating value
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.
2891
-
2892
-
When using the discriminator, _inline_ schemas will not be considered.
2892
+
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.
2893
+
This hint can be used to aid in serialization, deserialization, and validation.
2894
+
The Discriminator Object does this by implicitly or explicitly associating the possible values of a named property with alternative schemas.
2893
2895
2894
2896
##### Fixed Fields
2895
2897
Field Name | Type | Description
2896
2898
---|:---:|---
2897
-
<a name="propertyName"></a>propertyName | `string` | **REQUIRED**. The name of the property in the payload that will hold the discriminator value.
2898
-
<a name="discriminatorMapping"></a> mapping | Map[`string`, `string`] | An object to hold mappings between payload values and schema names or references.
2899
+
<a name="propertyName"></a>propertyName | `string` | **REQUIRED**. The name of the property in the payload that will hold the discriminating value. This property SHOULD be required in the payload schema, as the behavior when the property is absent is undefined.
2900
+
<a name="discriminatorMapping"></a> mapping | Map[`string`, `string`] | An object to hold mappings between payload values and schema names or URI references.
2899
2901
2900
2902
This object MAY be extended with [Specification Extensions](#specificationExtensions).
2901
2903
2902
-
The discriminator object is legal only when using one of the composite keywords `oneOf`, `anyOf`, `allOf`. Note that because the discriminating property's value is used as a component name and/or as the key in the `mapping` object, the behavior of any value that is not a string is undefined.
2904
+
##### Conditions for Using the Discriminator Object
2905
+
The Discriminator Object is legal only when using one of the composite keywords `oneOf`, `anyOf`, `allOf`.
2906
+
In both the `oneOf` and `anyOf` use cases, where those keywords are adjacent to `discriminator`, all possible schemas MUST be listed explicitly.
2907
+
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.
2908
+
2909
+
The behavior of any configuration of `oneOf`, `anyOf`, `allOf` and `discriminator` that is not described above is undefined.
2910
+
2911
+
##### Options for Mapping Values to Schemas
2912
+
The value of the property named in `propertyName` is used as the name of the associated schema under the [Components Object](#componentsObject), _unless_ a `mapping` is present for that value.
2913
+
The `mapping` entry maps a specific property value to either a different schema component name, or to a schema identified by a URI.
2914
+
When using implicit or explicit schema component names, inline `oneOf` or `anyOf` subschemas are not considered.
2915
+
The behavior of a `mapping` value that is both a valid schema name and a valid relative URI reference is implementation-defined, but it is RECOMMENDED that it be treated as a schema name.
2916
+
To ensure that an ambiguous value (e.g. `"foo"`) is treated as a relative URI reference by all implementations, authors MUST prefix it with the `"."` path segment (e.g. `"./foo"`).
2917
+
2918
+
Mapping keys MUST be string values, but tooling MAY convert response values to strings for comparison.
2919
+
However, the exact nature of such conversions are implementation-defined.
For these examples, assume all schemas are in the entry OpenAPI document; for handling of `discriminator` in referenced documents see [Resolving Implicit Connections](#resolvingImplicitConnections).
2903
2924
2904
2925
In OAS 3.0, a response payload MAY be described to be exactly one of any number of types:
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. Mapping keys MUST be string values, but tooling MAY convert response values to strings for comparison.
2975
+
Here the discriminating value of `dog` will map to the schema `#/components/schemas/Dog`, rather than the default (implicit) value of `#/components/schemas/dog`. If the discriminating value does not match an implicit or explicit mapping, no schema can be determined and validation SHOULD fail.
2955
2976
2956
2977
When used in conjunction with the `anyOf` construct, the use of the discriminator can avoid ambiguity where multiple schemas may satisfy a single payload.
2957
2978
2958
-
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.
2959
-
2960
-
For example:
2979
+
This example shows the `allOf` usage, which avoids needing to reference all child schemas in the parent:
0 commit comments