Skip to content

Commit a174bec

Browse files
committed
fix eval schema
1 parent 6f070a8 commit a174bec

File tree

4 files changed

+6
-34
lines changed

4 files changed

+6
-34
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,7 @@ public void setUnevaluatedPropertiesPresent(boolean set) {
260260
this.unevaluatedPropertiesPresent = set;
261261
}
262262

263-
public boolean setUnevaluatedItemsPresent(boolean set) {
264-
boolean existing = this.unevaluatedItemsPresent;
263+
public void setUnevaluatedItemsPresent(boolean set) {
265264
this.unevaluatedItemsPresent = set;
266-
return existing;
267265
}
268266
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
229229
*/
230230
protected boolean canShortCircuit(ExecutionContext executionContext) {
231231
if (hasUnevaluatedItemsInEvaluationPath(executionContext)) {
232-
return true;
232+
return false;
233233
}
234234
if (hasUnevaluatedPropertiesInEvaluationPath(executionContext)) {
235-
return true;
235+
return false;
236236
}
237237
return !executionContext.getExecutionConfig().isAnnotationCollectionEnabled();
238238
}

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
7171
}
7272

7373
// Add annotation
74-
if (collectAnnotations() || collectAnnotations(executionContext)) {
74+
if (hasUnevaluatedItemsInEvaluationPath(executionContext) || collectAnnotations(executionContext)) {
7575
// Tuples
7676
int items = node.isArray() ? node.size() : 1;
7777
int schemas = this.tupleSchema.size();
@@ -113,7 +113,7 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
113113
}
114114

115115
// Add annotation
116-
if (collectAnnotations() || collectAnnotations(executionContext)) {
116+
if (hasUnevaluatedItemsInEvaluationPath(executionContext) || collectAnnotations(executionContext)) {
117117
// Tuples
118118
int items = node.isArray() ? node.size() : 1;
119119
int schemas = this.tupleSchema.size();
@@ -192,21 +192,9 @@ public List<Schema> getTupleSchema() {
192192
return this.tupleSchema;
193193
}
194194

195-
private boolean collectAnnotations() {
196-
return hasUnevaluatedItemsValidator();
197-
}
198-
199-
private boolean hasUnevaluatedItemsValidator() {
200-
if (this.hasUnevaluatedItemsValidator == null) {
201-
this.hasUnevaluatedItemsValidator = hasAdjacentKeywordInEvaluationPath("unevaluatedItems");
202-
}
203-
return hasUnevaluatedItemsValidator;
204-
}
205-
206195
@Override
207196
public void preloadSchema() {
208197
preloadSchemas(this.tupleSchema);
209-
collectAnnotations(); // cache the flag
210198
}
211199

212200
}

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public class PropertiesValidator extends BaseKeywordValidator {
4444
public static final String PROPERTY = "properties";
4545
private final Map<String, Schema> schemas = new LinkedHashMap<>();
4646

47-
private Boolean hasUnevaluatedPropertiesValidator;
48-
4947
public PropertiesValidator(SchemaLocation schemaLocation, NodePath evaluationPath, JsonNode schemaNode, Schema parentSchema, SchemaContext schemaContext) {
5048
super(KeywordType.PROPERTIES, schemaNode, schemaLocation, parentSchema, schemaContext, evaluationPath);
5149
for (Iterator<Entry<String, JsonNode>> it = schemaNode.fields(); it.hasNext();) {
@@ -70,7 +68,7 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
7068
// throw new RuntimeException();
7169
// }
7270
Set<String> matchedInstancePropertyNames = null;
73-
boolean collectAnnotations = /*collectAnnotations() ||*/ collectAnnotations(executionContext);
71+
boolean collectAnnotations = hasUnevaluatedPropertiesInEvaluationPath(executionContext) || collectAnnotations(executionContext);
7472
for (Entry<String, Schema> entry : this.schemas.entrySet()) {
7573
JsonNode propertyNode = node.get(entry.getKey());
7674
if (propertyNode != null) {
@@ -142,17 +140,6 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
142140
}
143141
}
144142

145-
// private boolean collectAnnotations() {
146-
// return hasUnevaluatedPropertiesValidator();
147-
// }
148-
//
149-
// private boolean hasUnevaluatedPropertiesValidator() {
150-
// if (this.hasUnevaluatedPropertiesValidator == null) {
151-
// this.hasUnevaluatedPropertiesValidator = hasAdjacentKeywordInEvaluationPath("unevaluatedProperties");
152-
// }
153-
// return hasUnevaluatedPropertiesValidator;
154-
// }
155-
156143
private void applyPropertyDefaults(ObjectNode node, ExecutionContext executionContext) {
157144
for (Map.Entry<String, Schema> entry : this.schemas.entrySet()) {
158145
JsonNode propertyNode = node.get(entry.getKey());
@@ -208,6 +195,5 @@ public Map<String, Schema> getSchemas() {
208195
@Override
209196
public void preloadSchema() {
210197
preloadSchemas(this.schemas.values());
211-
// collectAnnotations(); // cache the flag
212198
}
213199
}

0 commit comments

Comments
 (0)