Skip to content

Commit 3a6dc23

Browse files
authored
fix: add required validation to if lesssons (#180) (#181)
* fix: add `required` validation to `if` lesssons (#180) Closes #180 This commit adds the `required` validation on the properties that have an `if` applicator condition applied to them in the *instructions* for the following lessons: - [05-Conditional-Validation/04-if-then-keyword](https://tour.json-schema.org/content/05-Conditional-Validation/04-if-then-keyword) - [https://tour.json-schema.org/content/05-Conditional-Validation/06-Expanding-If-then-else](https://tour.json-schema.org/content/05-Conditional-Validation/06-Expanding-If-then-else) * fix: move the `required` validation to the `if` schema This commit moves the `required` validation for the example schema in ch05's lesson "Expanding If-then-else" and places it in the `if` subschema, so that it applies only for the purpose of the condition.
1 parent 2264644 commit 3a6dc23

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

content/05-Conditional-Validation/04-if-then-keyword/instructions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can use the `if-then` keyword to enforce this condition.
2929
{
3030
"type": "object",
3131
"properties": {...},
32-
"if": {"properties": {"isFullTime": {"const": true}}},
32+
"if": {"properties": {"isFullTime": {"const": true}}, "required": ["isFullTime"]},
3333
"then": {"required": ["salary"]},
3434
}
3535
```

content/05-Conditional-Validation/06-Expanding-If-then-else/instructions.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Using the `not` keyword with the `if-else` keyword can look something like this:
4141
"if": {
4242
"properties": {
4343
"status": { "const": "employed" }
44-
}
44+
},
45+
"required": ["status"]
4546
},
4647
"then": {
4748
"not": { "required": ["unemploymentBenefits"]
@@ -70,4 +71,4 @@ You are given the [schema](https://json-schema.org/learn/glossary#schema) for th
7071
- **If** `grade` is **greater that or equal to 8**, **then** the `recommendationLetter` field must be present, and the `personalStatement` field must **NOT** be present.
7172
- Else if `grade` is **lower than 8**, **then** the `personalStatement` field must be present, and the `recommendationLetter` field must **NOT** be present..
7273

73-
> **Hint:** Use the `minimum` keyword to specify the constraint of greater than or equal to 8.
74+
> **Hint:** Use the `minimum` keyword to specify the constraint of greater than or equal to 8.

0 commit comments

Comments
 (0)