Skip to content

Commit

Permalink
Update the linter to also escape early for keywords having an unknown…
Browse files Browse the repository at this point in the history
… parent
  • Loading branch information
ssilverman committed Jun 22, 2020
1 parent 166ef81 commit c9403c9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/qindesign/json/schema/Linter.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ private static boolean is(List<String> path, String name) {
return path.get(path.size() - 1).equals(name);
}

/**
* Checks if the path ends with an unknown keyword.
*
* @param path the path
* @return whether the last element is unknown.
*/
private static boolean isUnknown(List<String> path) {
if (path.isEmpty()) {
return false;
}
return !KNOWN_KEYWORDS.contains(path.get(path.size() - 1));
}

/**
* Checks the given schema and returns lists of any issues found for each
* element in the tree. This returns a map of JSON element locations to a
Expand Down Expand Up @@ -290,8 +303,11 @@ public static Map<List<String>, List<String>> check(JsonElement schema) {
is(path, Definitions.NAME);
}

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

Expand Down

0 comments on commit c9403c9

Please sign in to comment.