Skip to content

Commit cb2fc46

Browse files
committed
Fix
1 parent a7a0f2d commit cb2fc46

File tree

4 files changed

+58
-33
lines changed

4 files changed

+58
-33
lines changed

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

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ public void validate(ExecutionContext executionContext, JsonNode jsonNode, JsonN
730730
// System.out.println("MISMATCH NEW: " + newEvaluationPath);
731731
// System.out.println("-----------------");
732732
// }
733+
List<KeywordValidator> validators = getValidators(); // Load the validators before checking the flags
733734
executionContext.evaluationSchema.addLast(this);
734735
boolean unevaluatedPropertiesPresent = executionContext.unevaluatedPropertiesPresent;
735736
boolean unevaluatedItemsPresent = executionContext.unevaluatedItemsPresent;
@@ -741,7 +742,7 @@ public void validate(ExecutionContext executionContext, JsonNode jsonNode, JsonN
741742
}
742743
try {
743744
int currentErrors = executionContext.getErrors().size();
744-
for (KeywordValidator v : getValidators()) {
745+
for (KeywordValidator v : validators) {
745746
executionContext.evaluationPath.addLast(v.getKeyword());
746747
executionContext.evaluationSchemaPath.addLast(v.getKeyword());
747748
try {
@@ -1626,29 +1627,47 @@ private <T> T walkAtNodeInternal(ExecutionContext executionContext, JsonNode nod
16261627
public void walk(ExecutionContext executionContext, JsonNode node, JsonNode rootNode,
16271628
NodePath instanceLocation, boolean shouldValidateSchema) {
16281629
// Walk through all the JSONWalker's.
1629-
int currentErrors = executionContext.getErrors().size();
1630-
for (KeywordValidator validator : getValidators()) {
1631-
NodePath evaluationPathWithKeyword = validator.getEvaluationPath();
1632-
try {
1633-
// Call all the pre-walk listeners. If at least one of the pre walk listeners
1634-
// returns SKIP, then skip the walk.
1635-
if (executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPreWalkListeners(executionContext,
1636-
evaluationPathWithKeyword.getName(-1), node, rootNode, instanceLocation,
1637-
this, validator)) {
1638-
executionContext.evaluationPath.addLast(validator.getKeyword());
1639-
try {
1640-
validator.walk(executionContext, node, rootNode, instanceLocation, shouldValidateSchema);
1641-
} finally {
1642-
executionContext.evaluationPath.removeLast();
1630+
List<KeywordValidator> validators = getValidators(); // Load the validators before checking the flags
1631+
executionContext.evaluationSchema.addLast(this);
1632+
boolean unevaluatedPropertiesPresent = executionContext.unevaluatedPropertiesPresent;
1633+
boolean unevaluatedItemsPresent = executionContext.unevaluatedItemsPresent;
1634+
if (this.unevaluatedPropertiesPresent) {
1635+
executionContext.unevaluatedPropertiesPresent = this.unevaluatedPropertiesPresent;
1636+
}
1637+
if (this.unevaluatedItemsPresent) {
1638+
executionContext.unevaluatedItemsPresent = this.unevaluatedItemsPresent;
1639+
}
1640+
try {
1641+
int currentErrors = executionContext.getErrors().size();
1642+
for (KeywordValidator validator : validators) {
1643+
NodePath evaluationPathWithKeyword = validator.getEvaluationPath();
1644+
try {
1645+
// Call all the pre-walk listeners. If at least one of the pre walk listeners
1646+
// returns SKIP, then skip the walk.
1647+
if (executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPreWalkListeners(executionContext,
1648+
evaluationPathWithKeyword.getName(-1), node, rootNode, instanceLocation,
1649+
this, validator)) {
1650+
executionContext.evaluationPath.addLast(validator.getKeyword());
1651+
executionContext.evaluationSchemaPath.addLast(validator.getKeyword());
1652+
try {
1653+
validator.walk(executionContext, node, rootNode, instanceLocation, shouldValidateSchema);
1654+
} finally {
1655+
executionContext.evaluationPath.removeLast();
1656+
executionContext.evaluationSchemaPath.removeLast();
1657+
}
16431658
}
1659+
} finally {
1660+
// Call all the post-walk listeners.
1661+
executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPostWalkListeners(executionContext,
1662+
evaluationPathWithKeyword.getName(-1), node, rootNode, instanceLocation,
1663+
this, validator,
1664+
executionContext.getErrors().subList(currentErrors, executionContext.getErrors().size()));
16441665
}
1645-
} finally {
1646-
// Call all the post-walk listeners.
1647-
executionContext.getWalkConfig().getKeywordWalkListenerRunner().runPostWalkListeners(executionContext,
1648-
evaluationPathWithKeyword.getName(-1), node, rootNode, instanceLocation,
1649-
this, validator,
1650-
executionContext.getErrors().subList(currentErrors, executionContext.getErrors().size()));
16511666
}
1667+
} finally {
1668+
executionContext.evaluationSchema.removeLast();
1669+
executionContext.unevaluatedPropertiesPresent = unevaluatedPropertiesPresent;
1670+
executionContext.unevaluatedItemsPresent = unevaluatedItemsPresent;
16521671
}
16531672
}
16541673

src/main/java/com/networknt/schema/keyword/DynamicRefValidator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.networknt.schema.SchemaLocation;
2929
import com.networknt.schema.SchemaContext;
3030

31+
import java.util.Iterator;
3132
import java.util.function.Supplier;
3233

3334
/**
@@ -123,11 +124,10 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
123124
}
124125
if (node == null) {
125126
// Check for circular dependency
126-
SchemaLocation schemaLocation = refSchema.getSchemaLocation();
127-
Schema check = refSchema;
128127
boolean circularDependency = false;
129-
while (check.getEvaluationParentSchema() != null) {
130-
check = check.getEvaluationParentSchema();
128+
SchemaLocation schemaLocation = refSchema.getSchemaLocation();
129+
for (Iterator<Schema> iter = executionContext.getEvaluationSchema().descendingIterator(); iter.hasNext();) {
130+
Schema check = iter.next();
131131
if (check.getSchemaLocation().equals(schemaLocation)) {
132132
circularDependency = true;
133133
break;
@@ -158,6 +158,7 @@ public void preloadSchema() {
158158
// Only one cycle is pre-loaded
159159
// The rest of the cycles will load at execution time depending on the input
160160
// data
161+
/*
161162
SchemaLocation schemaLocation = jsonSchema.getSchemaLocation();
162163
Schema check = jsonSchema;
163164
boolean circularDependency = false;
@@ -174,5 +175,6 @@ public void preloadSchema() {
174175
&& depth < this.schemaContext.getSchemaRegistryConfig().getPreloadSchemaRefMaxNestingDepth()) {
175176
jsonSchema.initializeValidators();
176177
}
178+
*/
177179
}
178180
}

src/main/java/com/networknt/schema/keyword/RecursiveRefValidator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.networknt.schema.SchemaLocation;
2929
import com.networknt.schema.SchemaContext;
3030

31+
import java.util.Iterator;
3132
import java.util.function.Supplier;
3233

3334
/**
@@ -120,11 +121,10 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
120121
}
121122
if (node == null) {
122123
// Check for circular dependency
123-
SchemaLocation schemaLocation = refSchema.getSchemaLocation();
124-
Schema check = refSchema;
125124
boolean circularDependency = false;
126-
while (check.getEvaluationParentSchema() != null) {
127-
check = check.getEvaluationParentSchema();
125+
SchemaLocation schemaLocation = refSchema.getSchemaLocation();
126+
for (Iterator<Schema> iter = executionContext.getEvaluationSchema().descendingIterator(); iter.hasNext();) {
127+
Schema check = iter.next();
128128
if (check.getSchemaLocation().equals(schemaLocation)) {
129129
circularDependency = true;
130130
break;
@@ -155,6 +155,7 @@ public void preloadSchema() {
155155
// Only one cycle is pre-loaded
156156
// The rest of the cycles will load at execution time depending on the input
157157
// data
158+
/*
158159
SchemaLocation schemaLocation = jsonSchema.getSchemaLocation();
159160
Schema check = jsonSchema;
160161
boolean circularDependency = false;
@@ -171,5 +172,6 @@ public void preloadSchema() {
171172
&& depth < this.schemaContext.getSchemaRegistryConfig().getPreloadSchemaRefMaxNestingDepth()) {
172173
jsonSchema.initializeValidators();
173174
}
175+
*/
174176
}
175177
}

src/main/java/com/networknt/schema/keyword/RefValidator.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.networknt.schema.SchemaLocation;
2929
import com.networknt.schema.SchemaContext;
3030

31+
import java.util.Iterator;
3132
import java.util.function.Supplier;
3233

3334
/**
@@ -209,11 +210,10 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
209210
}
210211
if (node == null) {
211212
// Check for circular dependency
212-
SchemaLocation schemaLocation = refSchema.getSchemaLocation();
213-
Schema check = refSchema;
214213
boolean circularDependency = false;
215-
while (check.getEvaluationParentSchema() != null) {
216-
check = check.getEvaluationParentSchema();
214+
SchemaLocation schemaLocation = refSchema.getSchemaLocation();
215+
for (Iterator<Schema> iter = executionContext.getEvaluationSchema().descendingIterator(); iter.hasNext();) {
216+
Schema check = iter.next();
217217
if (check.getSchemaLocation().equals(schemaLocation)) {
218218
circularDependency = true;
219219
break;
@@ -244,6 +244,7 @@ public void preloadSchema() {
244244
// Only one cycle is pre-loaded
245245
// The rest of the cycles will load at execution time depending on the input
246246
// data
247+
/*
247248
SchemaLocation schemaLocation = jsonSchema.getSchemaLocation();
248249
Schema check = jsonSchema;
249250
boolean circularDependency = false;
@@ -260,5 +261,6 @@ public void preloadSchema() {
260261
&& depth < this.schemaContext.getSchemaRegistryConfig().getPreloadSchemaRefMaxNestingDepth()) {
261262
jsonSchema.initializeValidators();
262263
}
264+
*/
263265
}
264266
}

0 commit comments

Comments
 (0)