Skip to content

Commit 1dd05c8

Browse files
committed
only check subschema if distinct from schema, and minor changes
1 parent 1778aa3 commit 1dd05c8

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/main/java/com/networknt/schema/BaseJsonValidator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,16 @@ protected JsonSchema getParentSchema() {
5656
protected JsonSchema getSubSchema() {
5757
return subSchema;
5858
}
59-
59+
6060
protected boolean hasSubSchema() {
6161
return subSchema != null;
6262
}
6363

6464
protected JsonSchema obainSubSchemaNode(JsonNode schemaNode){
6565
JsonNode node = schemaNode.get("id");
6666
if(node == null) return null;
67-
67+
if(node.equals(schemaNode.get("$schema"))) return null;
68+
6869
try {
6970
JsonSchemaFactory factory = new JsonSchemaFactory();
7071
URL url = new URL(node.textValue());

src/main/java/com/networknt/schema/JsonSchema.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ public class JsonSchema extends BaseJsonValidator {
6262
*/
6363
public JsonNode getRefSchemaNode(String ref) {
6464
JsonSchema schema = findAncestor();
65-
JsonNode schemaNode = schema.getSchemaNode();
66-
JsonNode node = null;
67-
65+
JsonNode node = schema.getSchemaNode();
66+
6867
if (ref.startsWith("#/")) {
6968
// handle local ref
7069
String[] keys = ref.substring(2).split("/");
@@ -75,13 +74,16 @@ public JsonNode getRefSchemaNode(String ref) {
7574
}
7675
Matcher matcher = intPattern.matcher(key);
7776
if (matcher.matches()) {
78-
node = schemaNode.get(Integer.parseInt(key));
77+
node = node.get(Integer.parseInt(key));
7978
} else {
80-
node = schemaNode.get(key);
79+
node = node.get(key);
8180
}
8281
if (node == null && schema.hasSubSchema()){
8382
node = schema.getSubSchema().getRefSchemaNode(ref);
8483
}
84+
if (node == null){
85+
break;
86+
}
8587
}
8688
}
8789
return node;

0 commit comments

Comments
 (0)