Skip to content

Commit e0920ac

Browse files
marcopiiiaeschli
andauthored
feat: make getMatchingSchemas return keys matching propertyNames schema (#279)
* feat: make getMatchingSchemas return keys matching propertyNames schema * test: add test for schema matching on propertyNames --------- Co-authored-by: Martin Aeschlimann <[email protected]>
1 parent 6877521 commit e0920ac

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/parser/jsonParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ function validate(n: ASTNode | undefined, schema: JSONSchema, validationResult:
10951095
for (const f of node.properties) {
10961096
const key = f.keyNode;
10971097
if (key) {
1098-
validate(key, propertyNames, validationResult, NoOpSchemaCollector.instance, context);
1098+
validate(key, propertyNames, validationResult, matchingSchemas, context);
10991099
}
11001100
}
11011101
}

src/test/schema.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,10 @@ suite('JSON Schema', () => {
17901790
baz: {
17911791
type: 'boolean',
17921792
$comment: 'baz',
1793+
},
1794+
key: {
1795+
type: 'string',
1796+
$comment: 'key',
17931797
}
17941798
},
17951799
properties: {
@@ -1806,6 +1810,9 @@ suite('JSON Schema', () => {
18061810
}
18071811
}
18081812
}
1813+
},
1814+
propertyNames: {
1815+
$ref: "#/definitions/key"
18091816
}
18101817
};
18111818

@@ -1824,6 +1831,7 @@ suite('JSON Schema', () => {
18241831
assert.fail("No node at offset " + nodeOffset);
18251832
}
18261833
assertMatchingSchema(ms, 0, 'schema');
1834+
assertMatchingSchema(ms, 1, 'key');
18271835
assertMatchingSchema(ms, 7, 'foo');
18281836
assertMatchingSchema(ms, 14, 'bar');
18291837
assertMatchingSchema(ms, 22, 'baz');

0 commit comments

Comments
 (0)