Skip to content

Commit 7ebde14

Browse files
committed
Use defaultMapping keyword in discriminator
1 parent 9faf031 commit 7ebde14

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/oas.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,7 +2877,7 @@ These keywords can be used to describe polymorphism, where a single field can ac
28772877

28782878
The OpenAPI specification extends the JSON Schema support for polymorphism by adding the [`discriminator`](#schema-discriminator) field.
28792879
When used, the `discriminator` indicates the name of the property that hints which schema of an `anyOf` or `oneOf` is expected to validate the structure of the model.
2880-
The discriminating property may be defined as required or optional, but when defined as an optional property the `discriminator` field must include a `default` field that specifies which schema of the `anyOf` or `oneOf` is expected to validate the structure of the model.
2880+
The discriminating property may be defined as required or optional, but when defined as an optional property the `discriminator` field must include a `defaultMapping` field that specifies which schema of the `anyOf` or `oneOf` is expected to validate the structure of the model when the discriminating property is not present.
28812881

28822882
There are two ways to define the value of a discriminator for an inheriting instance.
28832883

@@ -3372,9 +3372,9 @@ Note that `discriminator` MUST NOT change the validation outcome of the schema.
33723372

33733373
| Field Name | Type | Description |
33743374
| ---- | :----: | ---- |
3375-
| <a name="property-name"></a>propertyName | `string` | **REQUIRED**. The name of the discriminating property in the payload that will hold the discriminating value. The discriminating property may be defined as required or optional, but when defined as optional the `discriminator` field must include a `default` field that specifies which schema is expected to validate the structure of the model. |
3375+
| <a name="property-name"></a>propertyName | `string` | **REQUIRED**. The name of the discriminating property in the payload that will hold the discriminating value. The discriminating property may be defined as required or optional, but when defined as optional the `discriminator` field must include a `defaultMapping` field that specifies which schema is expected to validate the structure of the model when no discriminating property is present. |
33763376
| <a name="discriminator-mapping"></a> mapping | Map[`string`, `string`] | An object to hold mappings between payload values and schema names or URI references. |
3377-
| <a name="default"></a> default | `string` | The schema name or URI reference to a schema that is expected to validate the structure of the model when the discriminating property is not present in the payload. |
3377+
| <a name="default"></a> defaultMapping | `string` | The schema name or URI reference to a schema that is expected to validate the structure of the model when the discriminating property is not present in the payload. |
33783378

33793379
This object MAY be extended with [Specification Extensions](#specification-extensions).
33803380

@@ -3404,11 +3404,11 @@ However, the exact nature of such conversions are implementation-defined.
34043404

34053405
##### Optional discriminating property
34063406

3407-
When the discriminating property is defined as optional, the `discriminator` field must include a `default` field that specifies a schema that is expected to validate the structure of the model when the discriminating property is not present in the payload. This allows the schema to still be validated correctly even if the discriminator property is missing.
3407+
When the discriminating property is defined as optional, the `discriminator` field must include a `defaultMapping` field that specifies a schema that is expected to validate the structure of the model when the discriminating property is not present in the payload. This allows the schema to still be validated correctly even if the discriminator property is missing.
34083408

34093409
The primary use case for an optional discriminating property is to allow a schema to be extended with a discriminator without breaking existing clients that do not provide the discriminating property.
34103410

3411-
Typically the schema specified in the `default` field will specify that the discriminating property is not present, e.g.
3411+
Typically the schema specified in the `defaultMapping` field will specify that the discriminating property is not present, e.g.
34123412

34133413
```yaml
34143414
OtherPet:
@@ -3417,7 +3417,7 @@ OtherPet:
34173417
required: ['petType']
34183418
```
34193419

3420-
This will prevent the default schema from validating a payload that includes the discriminating property, which would cause a validation of the payload to fail when polymorphism is described using the `oneOf` JSON schema keyword.
3420+
This will prevent the default mapping schema from validating a payload that includes the discriminating property, which would cause a validation of the payload to fail when polymorphism is described using the `oneOf` JSON schema keyword.
34213421

34223422
##### Examples
34233423

@@ -3476,7 +3476,7 @@ Here the discriminating value of `dog` will map to the schema `#/components/sche
34763476

34773477
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.
34783478

3479-
When the discriminating property is defined as optional, the `discriminator` field must include a `default` field that specifies a schema of the `anyOf` or `oneOf` is expected to validate the structure of the model when the discriminating property is not present in the payload. This allows the schema to still be validated correctly even if the discriminator property is missing.
3479+
When the discriminating property is defined as optional, the `discriminator` field must include a `defaultMapping` field that specifies a schema of the `anyOf` or `oneOf` is expected to validate the structure of the model when the discriminating property is not present in the payload. This allows the schema to still be validated correctly even if the discriminator property is missing.
34803480

34813481
For example:
34823482

@@ -3489,7 +3489,7 @@ MyResponseType:
34893489
- $ref: '#/components/schemas/OtherPet'
34903490
discriminator:
34913491
propertyName: petType
3492-
default: OtherPet
3492+
defaultMapping: OtherPet
34933493
OtherPet:
34943494
type: object
34953495
not:

0 commit comments

Comments
 (0)