Skip to content

Commit f4e1869

Browse files
committed
Remove special handling of type in anyOf
1 parent f42ac2f commit f4e1869

File tree

2 files changed

+3
-43
lines changed

2 files changed

+3
-43
lines changed

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public class Schema implements Validator {
6969

7070
private boolean validatorsLoaded = false;
7171
private boolean recursiveAnchor = false;
72-
private TypeValidator typeValidator = null;
7372

7473
protected final JsonNode schemaNode;
7574
protected final Schema parentSchema;
@@ -263,7 +262,6 @@ private Schema(SchemaContext schemaContext, SchemaLocation schemaLocation,
263262
* @param validators the validators
264263
* @param validatorsLoaded whether the validators are preloaded
265264
* @param recursiveAnchor whether this is has a recursive anchor
266-
* @param typeValidator the type validator
267265
* @param id the id
268266
* @param suppressSubSchemaRetrieval to suppress sub schema retrieval
269267
* @param schemaNode the schema node
@@ -287,7 +285,6 @@ protected Schema(
287285
this.validators = validators;
288286
this.validatorsLoaded = validatorsLoaded;
289287
this.recursiveAnchor = recursiveAnchor;
290-
this.typeValidator = typeValidator;
291288
this.id = id;
292289

293290
this.schemaContext = schemaContext;
@@ -559,10 +556,6 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
559556

560557
if ("$ref".equals(pname)) {
561558
refValidator = validator;
562-
} else if ("type".equals(pname)) {
563-
if (validator instanceof TypeValidator) {
564-
this.typeValidator = (TypeValidator) validator;
565-
}
566559
}
567560
}
568561

@@ -594,6 +587,9 @@ private List<KeywordValidator> read(JsonNode schemaNode) {
594587
if (lhsName.equals("discriminator")) return -1;
595588
if (rhsName.equals("discriminator")) return 1;
596589

590+
if (lhsName.equals("type")) return -1;
591+
if (rhsName.equals("type")) return 1;
592+
597593
if (lhsName.equals("properties")) return -1;
598594
if (rhsName.equals("properties")) return 1;
599595
if (lhsName.equals("patternProperties")) return -1;
@@ -1566,19 +1562,6 @@ public String toString() {
15661562
return getSchemaNode().toString();
15671563
}
15681564

1569-
public boolean hasTypeValidator() {
1570-
return getTypeValidator() != null;
1571-
}
1572-
1573-
public TypeValidator getTypeValidator() {
1574-
// As the validators are lazy loaded the typeValidator is only known if the
1575-
// validators are not null
1576-
if (this.validators == null) {
1577-
getValidators();
1578-
}
1579-
return this.typeValidator;
1580-
}
1581-
15821565
public List<KeywordValidator> getValidators() {
15831566
if (this.validators == null) {
15841567
this.validators = Collections.unmodifiableList(read(getSchemaNode()));

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,6 @@ protected void validate(ExecutionContext executionContext, JsonNode node, JsonNo
7575
executionContext.setFailFast(false);
7676
for (Schema schema : this.schemas) {
7777
subSchemaErrors.clear(); // Reuse and clear for each run
78-
TypeValidator typeValidator = schema.getTypeValidator();
79-
if (typeValidator != null) {
80-
// If schema has type validator and node type doesn't match with schemaType then
81-
// ignore it
82-
// For union type, it is a must to call TypeValidator
83-
executionContext.evaluationPathAddLast(schemaIndex);
84-
executionContext.evaluationPathAddLast("type");
85-
try {
86-
87-
if (typeValidator.getSchemaType() != JsonType.UNION && !typeValidator.equalsToSchemaType(node, executionContext)) {
88-
typeValidator.validate(executionContext, node, rootNode, instanceLocation);
89-
if (allErrors == null) {
90-
allErrors = new ArrayList<>();
91-
}
92-
allErrors.addAll(subSchemaErrors);
93-
schemaIndex++;
94-
continue;
95-
}
96-
} finally {
97-
executionContext.evaluationPathRemoveLast();
98-
executionContext.evaluationPathRemoveLast();
99-
}
100-
}
10178
executionContext.evaluationPathAddLast(schemaIndex);
10279
try {
10380
if (!walk) {

0 commit comments

Comments
 (0)