Skip to content

Commit

Permalink
Adds support for walking if-then-else (#813)
Browse files Browse the repository at this point in the history
Resolves #603

Co-authored-by: Faron Dutton <faron.dutton@insightglobal.com>
  • Loading branch information
fdutton and Faron Dutton committed Jun 7, 2023
1 parent 9d78bf3 commit ac6ecd0
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/com/networknt/schema/IfValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,34 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String

@Override
public void preloadJsonSchema() {
if(null != this.ifSchema) {
if (null != this.ifSchema) {
this.ifSchema.initializeValidators();
}
if(null != this.thenSchema) {
if (null != this.thenSchema) {
this.thenSchema.initializeValidators();
}
if(null != this.elseSchema) {
if (null != this.elseSchema) {
this.elseSchema.initializeValidators();
}
}

@Override
public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
if (shouldValidateSchema) {
return validate(node, rootNode, at);
}

if (null != this.ifSchema) {
this.ifSchema.walk(node, rootNode, at, false);
}
if (null != this.thenSchema) {
this.thenSchema.walk(node, rootNode, at, false);
}
if (null != this.elseSchema) {
this.elseSchema.walk(node, rootNode, at, false);
}

return Collections.emptySet();
}

}

0 comments on commit ac6ecd0

Please sign in to comment.