Skip to content

Commit

Permalink
correct JTD discriminator docs
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed May 9, 2021
1 parent 13730a5 commit 0404a50
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/json-type-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ Invalid data: `{}`, `{foo: 1}`, `{foo: "bar", bar: "3"}`, any type other than ob

This form defines discriminated (tagged) union of different record types.

It has required members `discriminator` and `mappings` and optional members `nullable` and `metadata`, no other members are allowed.
It has required members `discriminator` and `mapping` and optional members `nullable` and `metadata`, no other members are allowed.

The string value of `discriminator` schema member contains the name of the data member that is the tag of the union. `mappings` schema member contains the dictionary of schemas that are applied according to the value of the tag member in the data. Schemas inside `mappings` must have "properties" form.
The string value of `discriminator` schema member contains the name of the data member that is the tag of the union. `mapping` schema member contains the dictionary of schemas that are applied according to the value of the tag member in the data. Schemas inside `mapping` must have "properties" form.

Properties forms inside `mappings` cannot be `nullable` and cannot define the same property as discriminator tag.
Properties forms inside `mapping` cannot be `nullable` and cannot define the same property as discriminator tag.

**Example 1.**

Expand All @@ -183,7 +183,7 @@ Schema:
```javascript
{
discriminator: "version",
mappings: {
mapping: {
"1": {
properties: {
foo: {type: "string"}
Expand All @@ -202,12 +202,12 @@ Valid data: `{version: "1", foo: "1"}`, `{version: "2", foo: 1}`

Invalid data: `{}`, `{foo: "1"}`, `{version: 1, foo: "1"}`, any type other than object

**Example 3: invalid schema (discriminator tag member defined in mappings)**
**Example 3: invalid schema (discriminator tag member defined in mapping)**

```javascript
{
discriminator: "version",
mappings: {
mapping: {
"1": {
properties: {
version: {enum: ["1"]},
Expand Down

0 comments on commit 0404a50

Please sign in to comment.