Skip to content

Commit a47333a

Browse files
committed
Update
1 parent 48c3818 commit a47333a

File tree

5 files changed

+57
-48
lines changed

5 files changed

+57
-48
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,14 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
710710

711711
@Override
712712
public void validate(ExecutionContext executionContext, JsonNode jsonNode, JsonNode rootNode, NodePath instanceLocation) {
713-
String newEvaluationPath = new EvaluationPath(executionContext.getEvaluationPath()).toString();
714-
String oldEvaluationPath = getEvaluationPath().toString();
715-
if (!oldEvaluationPath.equals(newEvaluationPath)) {
716-
System.out.println("-----------------");
717-
System.out.println("MISMATCH OLD: " + oldEvaluationPath);
718-
System.out.println("MISMATCH NEW: " + newEvaluationPath);
719-
System.out.println("-----------------");
720-
}
713+
// String newEvaluationPath = new EvaluationPath(executionContext.getEvaluationPath()).toString();
714+
// String oldEvaluationPath = getEvaluationPath().toString();
715+
// if (!oldEvaluationPath.equals(newEvaluationPath)) {
716+
// System.out.println("-----------------");
717+
// System.out.println("MISMATCH OLD: " + oldEvaluationPath);
718+
// System.out.println("MISMATCH NEW: " + newEvaluationPath);
719+
// System.out.println("-----------------");
720+
// }
721721
executionContext.evaluationSchema.addLast(this);
722722
try {
723723
int currentErrors = executionContext.getErrors().size();

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.networknt.schema.keyword;
1818

19-
import java.util.ArrayDeque;
2019
import java.util.Iterator;
2120
import java.util.function.Consumer;
2221

@@ -25,7 +24,6 @@
2524
import com.networknt.schema.Schema;
2625
import com.networknt.schema.SchemaLocation;
2726
import com.networknt.schema.annotation.Annotation;
28-
import com.networknt.schema.path.EvaluationPath;
2927
import com.networknt.schema.path.NodePath;
3028

3129
/**
@@ -99,6 +97,10 @@ public String toString() {
9997
* @return true if annotations should be reported
10098
*/
10199
protected boolean collectAnnotations(ExecutionContext executionContext) {
100+
boolean hasUnevaluatedProperties = hasAdjacentKeywordInEvaluationPath(executionContext, "unevaluatedProperties");
101+
if (hasUnevaluatedProperties) {
102+
return true;
103+
}
102104
return collectAnnotations(executionContext, getKeyword());
103105
}
104106

@@ -144,15 +146,15 @@ protected void putAnnotation(ExecutionContext executionContext, Consumer<Annotat
144146
protected boolean hasAdjacentKeywordInEvaluationPath(ExecutionContext executionContext, String keyword) {
145147
Iterator<Object> evaluationSchemaPathIterator = executionContext.getEvaluationSchemaPath().descendingIterator();
146148
Iterator<Schema> evaluationSchemaIterator = executionContext.getEvaluationSchema().descendingIterator();
149+
boolean stop = false;
147150

148-
ArrayDeque<Object> current = executionContext.getEvaluationSchemaPath().clone();
149-
151+
// ArrayDeque<Object> current = executionContext.getEvaluationSchemaPath().clone();
152+
//
150153
// Skip the first as this is the path pointing to the current keyword eg. properties eg /$ref/properties
151154
// What is needed is the evaluationPath pointing to the current evaluationSchema eg /$ref
152155
if (evaluationSchemaPathIterator.hasNext()) {
153-
evaluationSchemaPathIterator.next();
154-
155-
current.removeLast();
156+
evaluationSchemaPathIterator.next();
157+
// current.removeLast();
156158
}
157159

158160
while (evaluationSchemaIterator.hasNext()) {
@@ -162,19 +164,23 @@ protected boolean hasAdjacentKeywordInEvaluationPath(ExecutionContext executionC
162164
return true;
163165
}
164166
}
165-
String newPath = new EvaluationPath(current).toString();
166-
String oldPath = schema.getEvaluationPath().toString();
167-
if (!oldPath.equals(newPath)) {
168-
System.out.println("OLD: "+oldPath);
169-
System.out.println("NEW: "+newPath);
167+
// String newPath = new EvaluationPath(current).toString();
168+
// String oldPath = schema.getEvaluationPath().toString();
169+
// if (!oldPath.equals(newPath)) {
170+
// System.out.println("OLD: "+oldPath);
171+
// System.out.println("NEW: "+newPath);
172+
// }
173+
174+
if (stop) {
175+
return false;
170176
}
171-
172177
if (evaluationSchemaPathIterator.hasNext()) {
173178
Object evaluationPath = evaluationSchemaPathIterator.next();
174-
current.removeLast();
179+
// current.removeLast();
175180
if ("properties".equals(evaluationPath) || "items".equals(evaluationPath)) {
176-
// If there is a change in instance location then return false
177-
return false;
181+
// If there is a change in instance location then after the next schema
182+
// stop
183+
stop = true;
178184
}
179185
}
180186
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ private void walkSchema(ExecutionContext executionContext, Schema walkSchema, Js
363363
try {
364364
// TOREMOVE
365365
// MISMATCH TEST
366-
String newPath = new EvaluationPath(executionContext.getEvaluationPath()).toString();
367-
String oldPath = walkSchema.getEvaluationPath().toString();
368-
if (!newPath.equals(oldPath)) {
369-
throw new RuntimeException("mismatch: old " + oldPath + " new " + newPath);
370-
}
366+
// String newPath = new EvaluationPath(executionContext.getEvaluationPath()).toString();
367+
// String oldPath = walkSchema.getEvaluationPath().toString();
368+
// if (!newPath.equals(oldPath)) {
369+
// throw new RuntimeException("mismatch: old " + oldPath + " new " + newPath);
370+
// }
371371

372372
boolean executeWalk = executionContext.getWalkConfig().getItemWalkListenerRunner()
373373
.runPreWalkListeners(executionContext, keyword, node, rootNode, instanceLocation, walkSchema, this);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ private void walkSchema(ExecutionContext executionContext, Schema walkSchema, Js
153153

154154
// TOREMOVE
155155
// MISMATCH TEST
156-
String newPath = new EvaluationPath(executionContext.getEvaluationPath()).toString();
157-
String oldPath = walkSchema.getEvaluationPath().toString();
158-
if (!newPath.equals(oldPath)) {
159-
throw new RuntimeException("mismatch: old "+oldPath+" new "+newPath);
160-
}
156+
// String newPath = new EvaluationPath(executionContext.getEvaluationPath()).toString();
157+
// String oldPath = walkSchema.getEvaluationPath().toString();
158+
// if (!newPath.equals(oldPath)) {
159+
// throw new RuntimeException("mismatch: old "+oldPath+" new "+newPath);
160+
// }
161161
boolean executeWalk = executionContext.getWalkConfig().getItemWalkListenerRunner().runPreWalkListeners(
162162
executionContext,
163163
KeywordType.ITEMS.getValue(),

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
6464

6565
protected void validate(ExecutionContext executionContext, JsonNode node, JsonNode rootNode,
6666
NodePath instanceLocation, boolean walk) {
67-
68-
boolean c = hasAdjacentKeywordInEvaluationPath(executionContext, "unevaluatedProperties");
67+
// boolean present = hasUnevaluatedPropertiesValidator();
68+
// boolean check = hasAdjacentKeywordInEvaluationPath(executionContext, "unevaluatedProperties");
69+
// if (present != check) {
70+
// throw new RuntimeException();
71+
// }
6972
Set<String> matchedInstancePropertyNames = null;
70-
boolean collectAnnotations = collectAnnotations() || collectAnnotations(executionContext);
73+
boolean collectAnnotations = /*collectAnnotations() ||*/ collectAnnotations(executionContext);
7174
for (Entry<String, Schema> entry : this.schemas.entrySet()) {
7275
JsonNode propertyNode = node.get(entry.getKey());
7376
if (propertyNode != null) {
@@ -139,16 +142,16 @@ public void walk(ExecutionContext executionContext, JsonNode node, JsonNode root
139142
}
140143
}
141144

142-
private boolean collectAnnotations() {
143-
return hasUnevaluatedPropertiesValidator();
144-
}
145-
146-
private boolean hasUnevaluatedPropertiesValidator() {
147-
if (this.hasUnevaluatedPropertiesValidator == null) {
148-
this.hasUnevaluatedPropertiesValidator = hasAdjacentKeywordInEvaluationPath("unevaluatedProperties");
149-
}
150-
return hasUnevaluatedPropertiesValidator;
151-
}
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+
// }
152155

153156
private void applyPropertyDefaults(ObjectNode node, ExecutionContext executionContext) {
154157
for (Map.Entry<String, Schema> entry : this.schemas.entrySet()) {
@@ -205,6 +208,6 @@ public Map<String, Schema> getSchemas() {
205208
@Override
206209
public void preloadSchema() {
207210
preloadSchemas(this.schemas.values());
208-
collectAnnotations(); // cache the flag
211+
// collectAnnotations(); // cache the flag
209212
}
210213
}

0 commit comments

Comments
 (0)