Skip to content

Commit da97fbf

Browse files
committed
changing ArraySchemaValidatingVisitor to stop referencing both owner visitor and failureReporter
1 parent 9528d56 commit da97fbf

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

core/src/main/java/org/everit/json/schema/ArraySchemaValidatingVisitor.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class ArraySchemaValidatingVisitor extends Visitor {
1616

1717
private final Object subject;
1818

19-
private final FailureReporter failureReporter;
20-
2119
private final ValidatingVisitor owner;
2220

2321
private JSONArray arraySubject;
@@ -26,16 +24,15 @@ class ArraySchemaValidatingVisitor extends Visitor {
2624

2725
private int subjectLength;
2826

29-
public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, FailureReporter failureReporter) {
27+
public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner) {
3028
this.subject = subject;
3129
this.owner = requireNonNull(owner, "owner cannot be null");
32-
this.failureReporter = requireNonNull(failureReporter, "failureReporter cannot be null");
3330
}
3431

3532
@Override void visitArraySchema(ArraySchema arraySchema) {
3633
if (!(subject instanceof JSONArray)) {
3734
if (arraySchema.requiresArray()) {
38-
failureReporter.failure(JSONArray.class, subject);
35+
owner.failure(JSONArray.class, subject);
3936
}
4037
} else {
4138
this.arraySubject = (JSONArray) subject;
@@ -47,13 +44,13 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, Fai
4744

4845
@Override void visitMinItems(Integer minItems) {
4946
if (minItems != null && subjectLength < minItems) {
50-
failureReporter.failure("expected minimum item count: " + minItems + ", found: " + subjectLength, "minItems");
47+
owner.failure("expected minimum item count: " + minItems + ", found: " + subjectLength, "minItems");
5148
}
5249
}
5350

5451
@Override void visitMaxItems(Integer maxItems) {
5552
if (maxItems != null && maxItems < subjectLength) {
56-
failureReporter.failure("expected maximum item count: " + maxItems + ", found: " + subjectLength, "maxItems");
53+
owner.failure("expected maximum item count: " + maxItems + ", found: " + subjectLength, "maxItems");
5754
}
5855
}
5956

@@ -66,7 +63,7 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, Fai
6663
Object item = arraySubject.get(i);
6764
for (Object contained : uniques) {
6865
if (ObjectComparator.deepEquals(contained, item)) {
69-
failureReporter.failure("array items are not unique", "uniqueItems");
66+
owner.failure("array items are not unique", "uniqueItems");
7067
return;
7168
}
7269
}
@@ -88,14 +85,14 @@ public ArraySchemaValidatingVisitor(Object subject, ValidatingVisitor owner, Fai
8885
String idx = String.valueOf(index);
8986
ifFails(itemSchema, subject)
9087
.map(exc -> exc.prepend(idx))
91-
.ifPresent(failureReporter::failure);
88+
.ifPresent(owner::failure);
9289
}
9390

9491
@Override void visitAdditionalItems(boolean additionalItems) {
9592
List<Schema> itemSchemas = arraySchema.getItemSchemas();
9693
int itemSchemaCount = itemSchemas == null ? 0 : itemSchemas.size();
9794
if (itemSchemas != null && !additionalItems && subjectLength > itemSchemaCount) {
98-
failureReporter.failure(format("expected: [%d] array items, found: [%d]", itemSchemaCount, subjectLength), "items");
95+
owner.failure(format("expected: [%d] array items, found: [%d]", itemSchemaCount, subjectLength), "items");
9996
}
10097
}
10198

@@ -116,7 +113,7 @@ private void validateItemsAgainstSchema(IntStream indices, IntFunction<Schema> s
116113
String copyOfI = String.valueOf(i); // i is not effectively final so we copy it
117114
ifFails(schemaForIndex.apply(i), arraySubject.get(i))
118115
.map(exc -> exc.prepend(copyOfI))
119-
.ifPresent(failureReporter::failure);
116+
.ifPresent(owner::failure);
120117
}
121118
}
122119

@@ -134,6 +131,6 @@ private Optional<ValidationException> ifFails(Schema schema, Object input) {
134131
return;
135132
}
136133
}
137-
failureReporter.failure("expected at least one array item to match 'contains' schema", "contains");
134+
owner.failure("expected at least one array item to match 'contains' schema", "contains");
138135
}
139136
}

core/src/main/java/org/everit/json/schema/ValidatingVisitor.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private static boolean isNull(Object obj) {
2525
}
2626

2727
@Override void visitArraySchema(ArraySchema arraySchema) {
28-
arraySchema.accept(new ArraySchemaValidatingVisitor(subject, this, failureReporter));
28+
arraySchema.accept(new ArraySchemaValidatingVisitor(subject, this));
2929
}
3030

3131
@Override void visitBooleanSchema(BooleanSchema schema) {
@@ -83,6 +83,10 @@ private static boolean isNull(Object obj) {
8383
}
8484
}
8585

86+
@Override void visitObjectSchema(ObjectSchema objectSchema) {
87+
super.visitObjectSchema(objectSchema);
88+
}
89+
8690
ValidationException getFailureOfSchema(Schema schema, Object input) {
8791
Object origSubject = this.subject;
8892
this.subject = input;
@@ -96,4 +100,16 @@ void failIfErrorFound() {
96100
failureReporter.throwExceptionIfFailureFound();
97101
}
98102

103+
void failure(String message, String keyword) {
104+
failureReporter.failure(message, keyword);
105+
}
106+
107+
void failure(Class<?> expectedType, Object actualValue) {
108+
failureReporter.failure(expectedType, actualValue);
109+
}
110+
111+
void failure(ValidationException exc) {
112+
failureReporter.failure(exc);
113+
}
114+
99115
}

0 commit comments

Comments
 (0)