Skip to content

Commit c9403c9

Browse files
committed
Update the linter to also escape early for keywords having an unknown parent
1 parent 166ef81 commit c9403c9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/main/java/com/qindesign/json/schema/Linter.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ private static boolean is(List<String> path, String name) {
160160
return path.get(path.size() - 1).equals(name);
161161
}
162162

163+
/**
164+
* Checks if the path ends with an unknown keyword.
165+
*
166+
* @param path the path
167+
* @return whether the last element is unknown.
168+
*/
169+
private static boolean isUnknown(List<String> path) {
170+
if (path.isEmpty()) {
171+
return false;
172+
}
173+
return !KNOWN_KEYWORDS.contains(path.get(path.size() - 1));
174+
}
175+
163176
/**
164177
* Checks the given schema and returns lists of any issues found for each
165178
* element in the tree. This returns a map of JSON element locations to a
@@ -290,8 +303,11 @@ public static Map<List<String>, List<String>> check(JsonElement schema) {
290303
is(path, Definitions.NAME);
291304
}
292305

293-
// Allow anything directly below defs
294-
if (inDefs) {
306+
// Allow anything directly below defs or unknown keywords
307+
// Note that arrays will have a path that ends in a number, and so is
308+
// technically an unknown keyword; this is why we must also test for the
309+
// parent being an array
310+
if (inDefs || (isUnknown(path) && parent != null && !parent.isJsonArray())) {
295311
return;
296312
}
297313

0 commit comments

Comments
 (0)