Skip to content

Commit 9527f4a

Browse files
authored
Refactor evaluation context out from validator state (#1199)
1 parent e880dd0 commit 9527f4a

File tree

94 files changed

+1369
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1369
-1195
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.util.Objects;
1919

20+
import com.networknt.schema.utils.Strings;
21+
2022
/**
2123
* The absolute IRI is an IRI without the fragment.
2224
* <p>
@@ -131,7 +133,7 @@ public static String resolve(String parent, String iri) {
131133
}
132134
base = parent(base, scheme);
133135

134-
String[] iriParts = iri.split("/");
136+
String[] iriParts = Strings.split(iri, '/');
135137
for (int x = 0; x < iriParts.length; x++) {
136138
if ("..".equals(iriParts[x])) {
137139
base = parent(base, scheme);
@@ -149,9 +151,6 @@ public static String resolve(String parent, String iri) {
149151
}
150152
}
151153
}
152-
if (iri.endsWith("/")) {
153-
base = base + "/";
154-
}
155154
return base;
156155
}
157156
}

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

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

1717
package com.networknt.schema;
1818

19+
import java.util.ArrayDeque;
1920
import java.util.ArrayList;
2021
import java.util.HashMap;
2122
import java.util.List;
@@ -25,7 +26,7 @@
2526
import com.networknt.schema.annotation.Annotations;
2627
import com.networknt.schema.keyword.DiscriminatorState;
2728
import com.networknt.schema.path.NodePath;
28-
import com.networknt.schema.result.InstanceResults;
29+
//import com.networknt.schema.result.InstanceResults;
2930
import com.networknt.schema.walk.WalkConfig;
3031

3132
/**
@@ -37,11 +38,40 @@ public class ExecutionContext {
3738
private CollectorContext collectorContext = null;
3839

3940
private Annotations annotations = null;
40-
private InstanceResults instanceResults = null;
41+
// private InstanceResults instanceResults = null;
4142
private List<Error> errors = new ArrayList<>();
4243

43-
private Map<NodePath, DiscriminatorState> discriminatorMapping = new HashMap<>();
44+
private final Map<NodePath, DiscriminatorState> discriminatorMapping = new HashMap<>();
4445

46+
NodePath evaluationPath;
47+
final ArrayDeque<Schema> evaluationSchema = new ArrayDeque<>(64);
48+
final ArrayDeque<Object> evaluationSchemaPath = new ArrayDeque<>(64);
49+
50+
public NodePath getEvaluationPath() {
51+
return evaluationPath;
52+
}
53+
54+
public void evaluationPathAddLast(String token) {
55+
this.evaluationPath = evaluationPath.append(token);
56+
}
57+
58+
public void evaluationPathAddLast(int token) {
59+
this.evaluationPath = evaluationPath.append(token);
60+
}
61+
62+
public void evaluationPathRemoveLast() {
63+
this.evaluationPath = evaluationPath.getParent();
64+
}
65+
66+
67+
public ArrayDeque<Schema> getEvaluationSchema() {
68+
return evaluationSchema;
69+
}
70+
71+
public ArrayDeque<Object> getEvaluationSchemaPath() {
72+
return evaluationSchemaPath;
73+
}
74+
4575
public Map<NodePath, DiscriminatorState> getDiscriminatorMapping() {
4676
return discriminatorMapping;
4777
}
@@ -156,12 +186,12 @@ public Annotations getAnnotations() {
156186
return annotations;
157187
}
158188

159-
public InstanceResults getInstanceResults() {
160-
if (this.instanceResults == null) {
161-
this.instanceResults = new InstanceResults();
162-
}
163-
return instanceResults;
164-
}
189+
// public InstanceResults getInstanceResults() {
190+
// if (this.instanceResults == null) {
191+
// this.instanceResults = new InstanceResults();
192+
// }
193+
// return instanceResults;
194+
// }
165195

166196
/**
167197
* Determines if the validator should immediately throw a fail fast exception if
@@ -224,4 +254,24 @@ public void walkConfig(Consumer<WalkConfig.Builder> customizer) {
224254
customizer.accept(builder);
225255
this.walkConfig = builder.build();
226256
}
257+
258+
boolean unevaluatedPropertiesPresent = false;
259+
260+
boolean unevaluatedItemsPresent = false;
261+
262+
public boolean isUnevaluatedPropertiesPresent() {
263+
return this.unevaluatedPropertiesPresent;
264+
}
265+
266+
public boolean isUnevaluatedItemsPresent() {
267+
return this.unevaluatedItemsPresent;
268+
}
269+
270+
public void setUnevaluatedPropertiesPresent(boolean set) {
271+
this.unevaluatedPropertiesPresent = set;
272+
}
273+
274+
public void setUnevaluatedItemsPresent(boolean set) {
275+
this.unevaluatedItemsPresent = set;
276+
}
227277
}

0 commit comments

Comments
 (0)