Skip to content

Commit 65031a3

Browse files
author
Pascal Post
committed
add propertyNames
1 parent 5fec4d5 commit 65031a3

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The validator currently uses C++ regex implementation for pattern matching, requ
5151
- [x] pattern.json
5252
- [x] patternProperties.json
5353
- [x] properties.json
54-
- [ ] propertyNames.json
54+
- [x] propertyNames.json
5555
- [ ] ref.json
5656
- [ ] refRemote.json
5757
- [x] required.json

src/object.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,21 @@ pub fn checks(node: std.json.ObjectMap, data: std.json.Value, stack: *Stack, col
165165
}
166166
}
167167

168+
if (node.get("propertyNames")) |propertyNames| {
169+
try stack.pushPath("propertyNames");
170+
defer stack.pop();
171+
172+
var it = data.object.iterator();
173+
while (it.next()) |entry| {
174+
const key = entry.key_ptr.*;
175+
if (!try schema.checks(propertyNames, .{ .string = key }, stack, collect_errors)) {
176+
if (collect_errors) |errors| {
177+
const msg = try std.fmt.allocPrint(errors.arena.allocator(), "Invalid propertyNames for keyword {s}.", .{key});
178+
try errors.append(.{ .path = try stack.constructPath(errors.arena.allocator()), .msg = msg });
179+
} else return false;
180+
}
181+
}
182+
}
183+
168184
return if (collect_errors) |errors| errors.empty() else true;
169185
}

src/test_suite.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ test "run test suite" {
6565
"if-then-else.json",
6666
"contains.json",
6767
"default.json",
68+
"propertyNames.json",
6869
// "ref.json",
6970
// "WIP.json",
7071
};

0 commit comments

Comments
 (0)