1
1
package org .everit .json .schema ;
2
2
3
+ import static java .util .Arrays .asList ;
3
4
import static java .util .Objects .requireNonNull ;
5
+ import static org .everit .json .schema .listener .ConditionalSchemaValidationEvent .Keyword .ELSE ;
4
6
import static org .everit .json .schema .listener .ConditionalSchemaValidationEvent .Keyword .IF ;
5
7
import static org .everit .json .schema .listener .ConditionalSchemaValidationEvent .Keyword .THEN ;
6
8
7
- import java .util .Arrays ;
8
-
9
9
import org .everit .json .schema .listener .ConditionalSchemaMatchEvent ;
10
10
import org .everit .json .schema .listener .ConditionalSchemaMismatchEvent ;
11
+ import org .everit .json .schema .listener .ConditionalSchemaValidationEvent ;
11
12
12
13
class ConditionalSchemaValidatingVisitor extends Visitor {
13
14
@@ -38,8 +39,12 @@ void visitConditionalSchema(ConditionalSchema conditionalSchema) {
38
39
void visitIfSchema (Schema ifSchema ) {
39
40
if (conditionalSchema .getIfSchema ().isPresent ()) {
40
41
ifSchemaException = owner .getFailureOfSchema (ifSchema , subject );
42
+ if (ifSchemaException == null ) {
43
+ owner .validationListener .ifSchemaMatch (createMatchEvent (IF ));
44
+ } else {
45
+ owner .validationListener .ifSchemaMismatch (createMismatchEvent (IF , ifSchemaException ));
46
+ }
41
47
}
42
- owner .validationListener .ifSchemaMatch (new ConditionalSchemaMatchEvent (conditionalSchema , subject , IF ));
43
48
}
44
49
45
50
@ Override
@@ -50,15 +55,14 @@ void visitThenSchema(Schema thenSchema) {
50
55
ValidationException failure = new ValidationException (conditionalSchema ,
51
56
new StringBuilder (new StringBuilder ("#" )),
52
57
"input is invalid against the \" then\" schema" ,
53
- Arrays . asList (thenSchemaException ),
58
+ asList (thenSchemaException ),
54
59
"then" ,
55
60
conditionalSchema .getSchemaLocation ());
56
61
57
- owner .validationListener
58
- .thenSchemaMismatch (new ConditionalSchemaMismatchEvent (conditionalSchema , subject , THEN , thenSchemaException ));
62
+ owner .validationListener .thenSchemaMismatch (createMismatchEvent (THEN , thenSchemaException ));
59
63
owner .failure (failure );
60
64
} else {
61
- owner .validationListener .thenSchemaMatch (new ConditionalSchemaMatchEvent ( conditionalSchema , subject , THEN ));
65
+ owner .validationListener .thenSchemaMatch (createMatchEvent ( THEN ));
62
66
}
63
67
}
64
68
}
@@ -71,15 +75,24 @@ void visitElseSchema(Schema elseSchema) {
71
75
ValidationException failure = new ValidationException (conditionalSchema ,
72
76
new StringBuilder (new StringBuilder ("#" )),
73
77
"input is invalid against both the \" if\" and \" else\" schema" ,
74
- Arrays . asList (ifSchemaException , elseSchemaException ),
78
+ asList (ifSchemaException , elseSchemaException ),
75
79
"else" ,
76
80
conditionalSchema .getSchemaLocation ());
77
-
78
- // owner.reportSchemaMatchEvent(elseSchema, failure);
81
+ owner .validationListener .elseSchemaMismatch (createMismatchEvent (ELSE , elseSchemaException ));
79
82
owner .failure (failure );
83
+ } else {
84
+ owner .validationListener .elseSchemaMatch (createMatchEvent (ELSE ));
80
85
}
81
- // owner.reportSchemaMatchEvent(elseSchema, null);
82
86
}
83
87
}
84
88
89
+ private ConditionalSchemaMatchEvent createMatchEvent (ConditionalSchemaValidationEvent .Keyword keyword ) {
90
+ return new ConditionalSchemaMatchEvent (conditionalSchema , subject , keyword );
91
+ }
92
+
93
+ private ConditionalSchemaMismatchEvent createMismatchEvent (ConditionalSchemaValidationEvent .Keyword keyword ,
94
+ ValidationException failure ) {
95
+ return new ConditionalSchemaMismatchEvent (conditionalSchema , subject , keyword , failure );
96
+ }
97
+
85
98
}
0 commit comments