3
3
import static java .lang .String .format ;
4
4
import static org .everit .json .schema .EnumSchema .toJavaValue ;
5
5
6
- import java .util .ArrayList ;
7
- import java .util .Arrays ;
8
- import java .util .Collection ;
9
- import java .util .List ;
6
+ import java .util .*;
10
7
11
8
import org .json .JSONObject ;
12
9
@@ -146,23 +143,16 @@ void visitConditionalSchema(ConditionalSchema conditionalSchema) {
146
143
return ;
147
144
}
148
145
ValidationException ifSchemaException = getFailureOfSchema (conditionalSchema .getIfSchema ().get (), subject );
149
- if (ifSchemaException != null ) {
150
- if (conditionalSchema .getElseSchema ().isPresent ()) {
151
- ValidationException elseSchemaException = getFailureOfSchema (conditionalSchema .getElseSchema ().get (), subject );
152
- if (elseSchemaException != null ) {
153
- failureReporter .failure (new ValidationException (conditionalSchema ,
154
- new StringBuilder (new StringBuilder ("#" )),
155
- "Data is invalid for schema of both \" if\" and \" else\" " ,
156
- Arrays .asList (ifSchemaException , elseSchemaException ),
157
- "else" ,
158
- conditionalSchema .getSchemaLocation ()));
159
- }
160
- }
161
- return ;
146
+ if (ifSchemaException == null ) {
147
+ visitThenSchema (conditionalSchema );
148
+ } else {
149
+ visitElseSchema (conditionalSchema , ifSchemaException );
162
150
}
151
+ }
152
+
153
+ private void visitThenSchema (ConditionalSchema conditionalSchema ) {
163
154
if (conditionalSchema .getThenSchema ().isPresent ()) {
164
- Schema schema = conditionalSchema .getThenSchema ().get ();
165
- ValidationException thenSchemaException = getFailureOfSchema (schema , subject );
155
+ ValidationException thenSchemaException = getFailureOfSchema (conditionalSchema .getThenSchema ().get (), subject );
166
156
if (thenSchemaException != null ) {
167
157
failureReporter .failure (new ValidationException (conditionalSchema ,
168
158
new StringBuilder (new StringBuilder ("#" )),
@@ -174,6 +164,20 @@ void visitConditionalSchema(ConditionalSchema conditionalSchema) {
174
164
}
175
165
}
176
166
167
+ private void visitElseSchema (ConditionalSchema conditionalSchema , ValidationException ifSchemaException ) {
168
+ if (conditionalSchema .getElseSchema ().isPresent ()) {
169
+ ValidationException elseSchemaException = getFailureOfSchema (conditionalSchema .getElseSchema ().get (), subject );
170
+ if (elseSchemaException != null ) {
171
+ failureReporter .failure (new ValidationException (conditionalSchema ,
172
+ new StringBuilder (new StringBuilder ("#" )),
173
+ "Data is invalid for schema of both \" if\" and \" else\" " ,
174
+ Arrays .asList (ifSchemaException , elseSchemaException ),
175
+ "else" ,
176
+ conditionalSchema .getSchemaLocation ()));
177
+ }
178
+ }
179
+ }
180
+
177
181
ValidationException getFailureOfSchema (Schema schema , Object input ) {
178
182
Object origSubject = this .subject ;
179
183
this .subject = input ;
0 commit comments