Skip to content

Commit 02eb31f

Browse files
authored
Merge pull request #100 from ekzobrain/bugfix/99
Fix properties with undefined value validation
2 parents c3b2325 + e3a7dd3 commit 02eb31f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/keywords/properties.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,15 @@ describe("keyword : properties : validate", () => {
108108

109109
assert.deepEqual(errors.length, 1);
110110
});
111+
112+
it("should validate undefined properties with boolean schema `false`", () => {
113+
const { valid } = compileSchema({
114+
type: "object",
115+
properties: {
116+
header: false
117+
}
118+
}).validate({ header: undefined });
119+
120+
assert.equal(valid, true);
121+
});
111122
});

src/keywords/properties.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ function validateProperties({ node, data, pointer, path }: JsonSchemaValidatorPa
4242
const errors: ValidationResult[] = [];
4343
const properties = node.properties ?? {};
4444
Object.keys(data).forEach((propertyName) => {
45-
if (properties[propertyName] == null) {
45+
const value = getValue(data, propertyName);
46+
const propertyNode = properties[propertyName];
47+
48+
if (propertyNode == null || value === void 0) {
4649
return;
4750
}
48-
const propertyNode = properties[propertyName];
49-
const result = validateNode(propertyNode, getValue(data, propertyName), `${pointer}/${propertyName}`, path);
51+
52+
const result = validateNode(propertyNode, value, `${pointer}/${propertyName}`, path);
5053
errors.push(...result);
5154
});
5255
return errors;

0 commit comments

Comments
 (0)