Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions content/01-Getting-Started/04-Enumerated-Values/instructions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,48 @@ Now, try to modify the `hobbies` property on the <SideEditorLink/> with `enum` c
Values defined in `enum` are case-sensitive.

So `reading` and `Reading` are considered different values.
</GoodToKnowBox>

<GoodToKnowBox>
Instead of using `enum`, you can also use `anyOf` or `oneOf` to validate your data against a set of subschemas. They work similarly, but there's a key difference in how strict they are.

### anyOf (Recommended)

Generally `anyof` [keyword](https://json-schema.org/understanding-json-schema/reference/combining#anyOf) is preferred as it validate data against **any** (one or more) of the given subschemas.

**Example:**
```json
{
"department": {
"anyOf": [
{ "const": "engineering" },
{ "const": "marketing" },
{ "const": "sales" },
{ "const": "HR" },
{ "const": "finance" }
]
}
}
```

### oneOf

The `oneOf` [keyword](https://json-schema.org/understanding-json-schema/reference/combining#oneOf) is stricter—it validates only when your data matches exactly one subschema. Since it has to check all possibilities to ensure only one matches, ***it can take longer to process***.

**Example:**
```json
{
"department": {
"oneOf": [
{ "const": "engineering" },
{ "const": "marketing" },
{ "const": "sales" },
{ "const": "HR" },
{ "const": "finance" }
]
}
}
```

In this department example, both approaches work identically since each value can only match one const at a time. But stick with `anyOf` as a general practice—it'll save you trouble down the road when your schemas get more complex.
</GoodToKnowBox>