diff --git a/content/01-Getting-Started/04-Enumerated-Values/instructions.mdx b/content/01-Getting-Started/04-Enumerated-Values/instructions.mdx index ba3db60..b37ec62 100644 --- a/content/01-Getting-Started/04-Enumerated-Values/instructions.mdx +++ b/content/01-Getting-Started/04-Enumerated-Values/instructions.mdx @@ -41,4 +41,48 @@ Now, try to modify the `hobbies` property on the with `enum` c Values defined in `enum` are case-sensitive. So `reading` and `Reading` are considered different values. + + + +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. \ No newline at end of file