Skip to content

Commit ac6ecd0

Browse files
fduttonFaron Dutton
andauthored
Adds support for walking if-then-else (#813)
Resolves #603 Co-authored-by: Faron Dutton <[email protected]>
1 parent 9d78bf3 commit ac6ecd0

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,34 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
9797

9898
@Override
9999
public void preloadJsonSchema() {
100-
if(null != this.ifSchema) {
100+
if (null != this.ifSchema) {
101101
this.ifSchema.initializeValidators();
102102
}
103-
if(null != this.thenSchema) {
103+
if (null != this.thenSchema) {
104104
this.thenSchema.initializeValidators();
105105
}
106-
if(null != this.elseSchema) {
106+
if (null != this.elseSchema) {
107107
this.elseSchema.initializeValidators();
108108
}
109109
}
110+
111+
@Override
112+
public Set<ValidationMessage> walk(JsonNode node, JsonNode rootNode, String at, boolean shouldValidateSchema) {
113+
if (shouldValidateSchema) {
114+
return validate(node, rootNode, at);
115+
}
116+
117+
if (null != this.ifSchema) {
118+
this.ifSchema.walk(node, rootNode, at, false);
119+
}
120+
if (null != this.thenSchema) {
121+
this.thenSchema.walk(node, rootNode, at, false);
122+
}
123+
if (null != this.elseSchema) {
124+
this.elseSchema.walk(node, rootNode, at, false);
125+
}
126+
127+
return Collections.emptySet();
128+
}
129+
110130
}

0 commit comments

Comments
 (0)