Skip to content

Commit 0eb1c85

Browse files
committed
Refactor and fix eval
1 parent 4f64756 commit 0eb1c85

File tree

90 files changed

+656
-844
lines changed

Some content is hidden

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

90 files changed

+656
-844
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2525
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
2626
import com.networknt.schema.i18n.MessageFormatter;
27+
import com.networknt.schema.path.EvaluationPath;
2728
import com.networknt.schema.path.NodePath;
2829
import com.networknt.schema.utils.CachingSupplier;
2930
import com.networknt.schema.utils.Strings;
3031

3132
import java.text.MessageFormat;
33+
import java.util.ArrayDeque;
3234
import java.util.Arrays;
3335
import java.util.HashMap;
3436
import java.util.Map;
@@ -49,7 +51,7 @@
4951
public class Error {
5052
private final String keyword;
5153
@JsonSerialize(using = ToStringSerializer.class)
52-
private final NodePath evaluationPath;
54+
private final EvaluationPath evaluationPath;
5355
@JsonSerialize(using = ToStringSerializer.class)
5456
private final SchemaLocation schemaLocation;
5557
@JsonSerialize(using = ToStringSerializer.class)
@@ -61,7 +63,7 @@ public class Error {
6163
private final JsonNode instanceNode;
6264
private final JsonNode schemaNode;
6365

64-
Error(String keyword, NodePath evaluationPath, SchemaLocation schemaLocation,
66+
Error(String keyword, EvaluationPath evaluationPath, SchemaLocation schemaLocation,
6567
NodePath instanceLocation, Object[] arguments, Map<String, Object> details,
6668
String messageKey, Supplier<String> messageSupplier, JsonNode instanceNode, JsonNode schemaNode) {
6769
super();
@@ -94,7 +96,7 @@ public NodePath getInstanceLocation() {
9496
*
9597
* @return the evaluation path
9698
*/
97-
public NodePath getEvaluationPath() {
99+
public EvaluationPath getEvaluationPath() {
98100
return evaluationPath;
99101
}
100102

@@ -240,7 +242,7 @@ public static abstract class BuilderSupport<S> {
240242
public abstract S self();
241243

242244
protected String keyword;
243-
protected NodePath evaluationPath;
245+
protected EvaluationPath evaluationPath;
244246
protected SchemaLocation schemaLocation;
245247
protected NodePath instanceLocation;
246248
protected Object[] arguments;
@@ -309,11 +311,16 @@ public S schemaLocation(SchemaLocation schemaLocation) {
309311
* @param evaluationPath the evaluation path
310312
* @return the builder
311313
*/
312-
public S evaluationPath(NodePath evaluationPath) {
314+
public S evaluationPath(EvaluationPath evaluationPath) {
313315
this.evaluationPath = evaluationPath;
314316
return self();
315317
}
316318

319+
public S evaluationPath(ArrayDeque<Object> evaluationPath) {
320+
this.evaluationPath = new EvaluationPath(evaluationPath);
321+
return self();
322+
}
323+
317324
public S arguments(Object... arguments) {
318325
this.arguments = arguments;
319326
return self();
@@ -399,7 +406,7 @@ protected String getKeyword() {
399406
return keyword;
400407
}
401408

402-
protected NodePath getEvaluationPath() {
409+
protected EvaluationPath getEvaluationPath() {
403410
return evaluationPath;
404411
}
405412

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
import java.util.ArrayDeque;
2020
import java.util.ArrayList;
2121
import java.util.HashMap;
22-
import java.util.Iterator;
2322
import java.util.List;
2423
import java.util.Map;
2524
import java.util.function.Consumer;
2625

2726
import com.networknt.schema.annotation.Annotations;
2827
import com.networknt.schema.keyword.DiscriminatorState;
29-
import com.networknt.schema.keyword.KeywordValidator;
3028
import com.networknt.schema.path.NodePath;
3129
import com.networknt.schema.result.InstanceResults;
3230
import com.networknt.schema.walk.WalkConfig;

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

Lines changed: 30 additions & 126 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.fasterxml.jackson.databind.JsonNode;
2323
import com.networknt.schema.dialect.Dialect;
2424
import com.networknt.schema.keyword.KeywordValidator;
25-
import com.networknt.schema.path.NodePath;
2625

2726
/**
2827
* The schema context associated with a schema and all its validators.
@@ -118,13 +117,13 @@ public SchemaContext(Dialect dialect, SchemaRegistry schemaRegistry,
118117
}
119118
}
120119

121-
public Schema newSchema(SchemaLocation schemaLocation, NodePath evaluationPath, JsonNode schemaNode, Schema parentSchema) {
122-
return getSchemaRegistry().create(this, schemaLocation, evaluationPath, schemaNode, parentSchema);
120+
public Schema newSchema(SchemaLocation schemaLocation, JsonNode schemaNode, Schema parentSchema) {
121+
return getSchemaRegistry().create(this, schemaLocation, schemaNode, parentSchema);
123122
}
124123

125-
public KeywordValidator newValidator(SchemaLocation schemaLocation, NodePath evaluationPath,
124+
public KeywordValidator newValidator(SchemaLocation schemaLocation,
126125
String keyword /* keyword */, JsonNode schemaNode, Schema parentSchema) {
127-
return this.dialect.newValidator(this, schemaLocation, evaluationPath, keyword, schemaNode, parentSchema);
126+
return this.dialect.newValidator(this, schemaLocation, keyword, schemaNode, parentSchema);
128127
}
129128

130129
public String resolveSchemaId(JsonNode schemaNode) {

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.networknt.schema.dialect.Dialect;
2323
import com.networknt.schema.dialect.DialectId;
2424
import com.networknt.schema.dialect.DialectRegistry;
25-
import com.networknt.schema.path.NodePath;
2625
import com.networknt.schema.resource.InputStreamSource;
2726
import com.networknt.schema.resource.ResourceLoaders;
2827
import com.networknt.schema.resource.SchemaIdResolvers;
@@ -456,7 +455,7 @@ public SchemaLoader getSchemaLoader() {
456455
protected Schema newSchema(SchemaLocation schemaUri, JsonNode schemaNode) {
457456
final SchemaContext schemaContext = createSchemaContext(schemaNode);
458457
Schema jsonSchema = doCreate(schemaContext, getSchemaLocation(schemaUri),
459-
new NodePath(schemaContext.getSchemaRegistryConfig().getPathType()), schemaNode, null, false);
458+
schemaNode, null, false);
460459
preload(jsonSchema);
461460
return jsonSchema;
462461
}
@@ -485,14 +484,14 @@ private void preload(Schema schema) {
485484
}
486485
}
487486

488-
public Schema create(SchemaContext schemaContext, SchemaLocation schemaLocation, NodePath evaluationPath,
487+
public Schema create(SchemaContext schemaContext, SchemaLocation schemaLocation,
489488
JsonNode schemaNode, Schema parentSchema) {
490-
return doCreate(schemaContext, schemaLocation, evaluationPath, schemaNode, parentSchema, false);
489+
return doCreate(schemaContext, schemaLocation, schemaNode, parentSchema, false);
491490
}
492491

493-
private Schema doCreate(SchemaContext schemaContext, SchemaLocation schemaLocation, NodePath evaluationPath,
492+
private Schema doCreate(SchemaContext schemaContext, SchemaLocation schemaLocation,
494493
JsonNode schemaNode, Schema parentSchema, boolean suppressSubSchemaRetrieval) {
495-
return Schema.from(withDialect(schemaContext, schemaNode), schemaLocation, evaluationPath, schemaNode,
494+
return Schema.from(withDialect(schemaContext, schemaNode), schemaLocation, schemaNode,
496495
parentSchema, suppressSubSchemaRetrieval);
497496
}
498497

@@ -696,17 +695,16 @@ protected Schema getMappedSchema(final SchemaLocation schemaUri) {
696695
}
697696

698697
final Dialect dialect = getDialectOrDefault(schemaNode);
699-
NodePath evaluationPath = new NodePath(getSchemaRegistryConfig().getPathType());
700698
if (schemaUri.getFragment() == null || schemaUri.getFragment().getNameCount() == 0) {
701699
// Schema without fragment
702700
SchemaContext schemaContext = new SchemaContext(dialect, this);
703-
return doCreate(schemaContext, schemaUri, evaluationPath, schemaNode, null,
701+
return doCreate(schemaContext, schemaUri, schemaNode, null,
704702
true /* retrieved via id, resolving will not change anything */);
705703
} else {
706704
// Schema with fragment pointing to sub schema
707705
final SchemaContext schemaContext = createSchemaContext(schemaNode);
708706
SchemaLocation documentLocation = new SchemaLocation(schemaUri.getAbsoluteIri());
709-
Schema document = doCreate(schemaContext, documentLocation, evaluationPath, schemaNode, null,
707+
Schema document = doCreate(schemaContext, documentLocation, schemaNode, null,
710708
false);
711709
return document.getRefSchema(schemaUri.getFragment());
712710
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,4 @@ default void walk(ExecutionContext executionContext, JsonNode instanceNode, Json
6363
* @return the schema location
6464
*/
6565
SchemaLocation getSchemaLocation();
66-
67-
/**
68-
* The evaluation path is the set of keys, starting from the schema root,
69-
* through which evaluation passes to reach the schema object that produced a
70-
* specific result.
71-
*
72-
* @return the evaluation path
73-
*/
74-
NodePath getEvaluationPath();
7566
}

src/main/java/com/networknt/schema/annotation/Annotation.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
*/
1616
package com.networknt.schema.annotation;
1717

18+
import java.util.ArrayDeque;
1819
import java.util.Objects;
1920

2021
import com.networknt.schema.SchemaLocation;
2122
import com.networknt.schema.keyword.Keyword;
23+
import com.networknt.schema.path.EvaluationPath;
2224
import com.networknt.schema.path.NodePath;
2325

2426
/**
@@ -28,11 +30,11 @@ public class Annotation {
2830
private final String keyword;
2931
private final NodePath instanceLocation;
3032
private final SchemaLocation schemaLocation;
31-
private final NodePath evaluationPath;
33+
private final EvaluationPath evaluationPath;
3234
private final Object value;
3335

3436
public Annotation(String keyword, NodePath instanceLocation, SchemaLocation schemaLocation,
35-
NodePath evaluationPath, Object value) {
37+
EvaluationPath evaluationPath, Object value) {
3638
super();
3739
this.keyword = keyword;
3840
this.instanceLocation = instanceLocation;
@@ -75,7 +77,7 @@ public SchemaLocation getSchemaLocation() {
7577
*
7678
* @return the evaluation path
7779
*/
78-
public NodePath getEvaluationPath() {
80+
public EvaluationPath getEvaluationPath() {
7981
return evaluationPath;
8082
}
8183

@@ -123,7 +125,7 @@ public static class Builder {
123125
private String keyword;
124126
private NodePath instanceLocation;
125127
private SchemaLocation schemaLocation;
126-
private NodePath evaluationPath;
128+
private EvaluationPath evaluationPath;
127129
private Object value;
128130

129131
public Builder keyword(Keyword keyword) {
@@ -146,11 +148,16 @@ public Builder schemaLocation(SchemaLocation schemaLocation) {
146148
return this;
147149
}
148150

149-
public Builder evaluationPath(NodePath evaluationPath) {
151+
public Builder evaluationPath(EvaluationPath evaluationPath) {
150152
this.evaluationPath = evaluationPath;
151153
return this;
152154
}
153155

156+
public Builder evaluationPath(ArrayDeque<Object> evaluationPath) {
157+
this.evaluationPath = new EvaluationPath(evaluationPath);
158+
return this;
159+
}
160+
154161
public Builder value(Object value) {
155162
this.value = value;
156163
return this;

src/main/java/com/networknt/schema/annotation/AnnotationPredicate.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
import java.util.function.Predicate;
1919

2020
import com.networknt.schema.SchemaLocation;
21+
import com.networknt.schema.path.EvaluationPath;
2122
import com.networknt.schema.path.NodePath;
2223

2324
/**
2425
* A predicate for filtering annotations.
2526
*/
2627
public class AnnotationPredicate implements Predicate<Annotation> {
2728
final Predicate<NodePath> instanceLocationPredicate;
28-
final Predicate<NodePath> evaluationPathPredicate;
29+
final Predicate<EvaluationPath> evaluationPathPredicate;
2930
final Predicate<SchemaLocation> schemaLocationPredicate;
3031
final Predicate<String> keywordPredicate;
3132
final Predicate<Object> valuePredicate;
@@ -40,7 +41,7 @@ public class AnnotationPredicate implements Predicate<Annotation> {
4041
* @param valuePredicate for value
4142
*/
4243
protected AnnotationPredicate(Predicate<NodePath> instanceLocationPredicate,
43-
Predicate<NodePath> evaluationPathPredicate, Predicate<SchemaLocation> schemaLocationPredicate,
44+
Predicate<EvaluationPath> evaluationPathPredicate, Predicate<SchemaLocation> schemaLocationPredicate,
4445
Predicate<String> keywordPredicate, Predicate<Object> valuePredicate) {
4546
super();
4647
this.instanceLocationPredicate = instanceLocationPredicate;
@@ -73,7 +74,7 @@ public Predicate<NodePath> getInstanceLocationPredicate() {
7374
*
7475
* @return the predicate
7576
*/
76-
public Predicate<NodePath> getEvaluationPathPredicate() {
77+
public Predicate<EvaluationPath> getEvaluationPathPredicate() {
7778
return evaluationPathPredicate;
7879
}
7980

@@ -118,7 +119,7 @@ public static Builder builder() {
118119
*/
119120
public static class Builder {
120121
Predicate<NodePath> instanceLocationPredicate;
121-
Predicate<NodePath> evaluationPathPredicate;
122+
Predicate<EvaluationPath> evaluationPathPredicate;
122123
Predicate<SchemaLocation> schemaLocationPredicate;
123124
Predicate<String> keywordPredicate;
124125
Predicate<Object> valuePredicate;
@@ -128,7 +129,7 @@ public Builder instanceLocation(Predicate<NodePath> instanceLocationPredicate) {
128129
return this;
129130
}
130131

131-
public Builder evaluationPath(Predicate<NodePath> evaluationPathPredicate) {
132+
public Builder evaluationPath(Predicate<EvaluationPath> evaluationPathPredicate) {
132133
this.evaluationPathPredicate = evaluationPathPredicate;
133134
return this;
134135
}

src/main/java/com/networknt/schema/dialect/Dialect.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.networknt.schema.keyword.KeywordFactory;
3131
import com.networknt.schema.keyword.KeywordValidator;
3232
import com.networknt.schema.keyword.UnknownKeywordFactory;
33-
import com.networknt.schema.path.NodePath;
3433
import com.networknt.schema.keyword.KeywordType;
3534
import com.networknt.schema.utils.Strings;
3635
import com.networknt.schema.vocabulary.Vocabularies;
@@ -441,14 +440,13 @@ public SpecificationVersion getSpecificationVersion() {
441440
*
442441
* @param schemaContext the schema context
443442
* @param schemaLocation the schema location
444-
* @param evaluationPath the evaluation path
445443
* @param keyword the keyword
446444
* @param schemaNode the schema node
447445
* @param parentSchema the parent schema
448446
* @return the validator
449447
*/
450448
public KeywordValidator newValidator(SchemaContext schemaContext, SchemaLocation schemaLocation,
451-
NodePath evaluationPath, String keyword, JsonNode schemaNode, Schema parentSchema) {
449+
String keyword, JsonNode schemaNode, Schema parentSchema) {
452450
try {
453451
Keyword kw = this.keywords.get(keyword);
454452
if (kw == null) {
@@ -460,7 +458,7 @@ public KeywordValidator newValidator(SchemaContext schemaContext, SchemaLocation
460458
}
461459
if (KeywordType.DISCRIMINATOR.getValue().equals(keyword)
462460
&& schemaContext.isDiscriminatorKeywordEnabled()) {
463-
return KeywordType.DISCRIMINATOR.newValidator(schemaLocation, evaluationPath, schemaNode,
461+
return KeywordType.DISCRIMINATOR.newValidator(schemaLocation, schemaNode,
464462
parentSchema, schemaContext);
465463
}
466464
kw = this.builder.unknownKeywordFactory != null
@@ -470,7 +468,7 @@ public KeywordValidator newValidator(SchemaContext schemaContext, SchemaLocation
470468
return null;
471469
}
472470
}
473-
return kw.newValidator(schemaLocation, evaluationPath, schemaNode, parentSchema, schemaContext);
471+
return kw.newValidator(schemaLocation, schemaNode, parentSchema, schemaContext);
474472
} catch (InvocationTargetException e) {
475473
if (e.getTargetException() instanceof SchemaException) {
476474
logger.error("Error:", e);

src/main/java/com/networknt/schema/format/BaseFormatValidator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
import com.networknt.schema.SpecificationVersion;
1111
import com.networknt.schema.keyword.BaseKeywordValidator;
1212
import com.networknt.schema.keyword.Keyword;
13-
import com.networknt.schema.path.NodePath;
1413

1514
public abstract class BaseFormatValidator extends BaseKeywordValidator {
1615
protected final boolean assertionsEnabled;
1716

18-
public BaseFormatValidator(SchemaLocation schemaLocation, NodePath evaluationPath, JsonNode schemaNode,
17+
public BaseFormatValidator(SchemaLocation schemaLocation, JsonNode schemaNode,
1918
Schema parentSchema, Keyword keyword,
2019
SchemaContext schemaContext) {
21-
super(keyword, schemaNode, schemaLocation, parentSchema, schemaContext, evaluationPath);
20+
super(keyword, schemaNode, schemaLocation, parentSchema, schemaContext);
2221
SpecificationVersion dialect = this.schemaContext.getDialect().getSpecificationVersion();
2322
if (dialect == null || dialect.getOrder() < SpecificationVersion.DRAFT_2019_09.getOrder()) {
2423
assertionsEnabled = true;

0 commit comments

Comments
 (0)