12
12
use JsonSchema \ConstraintError ;
13
13
use JsonSchema \Constraints \TypeCheck \LooseTypeCheck ;
14
14
use JsonSchema \Entity \JsonPointer ;
15
+ use JsonSchema \Exception \ValidationException ;
15
16
use JsonSchema \Uri \UriResolver ;
16
17
17
18
/**
@@ -245,11 +246,16 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
245
246
if (isset ($ schema ->anyOf )) {
246
247
$ isValid = false ;
247
248
$ startErrors = $ this ->getErrors ();
249
+ $ caughtException = null ;
248
250
foreach ($ schema ->anyOf as $ anyOf ) {
249
251
$ initErrors = $ this ->getErrors ();
250
- $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i );
251
- if ($ isValid = (count ($ this ->getErrors ()) == count ($ initErrors ))) {
252
- break ;
252
+ try {
253
+ $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i );
254
+ if ($ isValid = (count ($ this ->getErrors ()) == count ($ initErrors ))) {
255
+ break ;
256
+ }
257
+ } catch (ValidationException $ e ) {
258
+ $ isValid = false ;
253
259
}
254
260
}
255
261
if (!$ isValid ) {
@@ -264,12 +270,17 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
264
270
$ matchedSchemas = 0 ;
265
271
$ startErrors = $ this ->getErrors ();
266
272
foreach ($ schema ->oneOf as $ oneOf ) {
267
- $ this ->errors = array ();
268
- $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i );
269
- if (count ($ this ->getErrors ()) == 0 ) {
270
- $ matchedSchemas ++;
273
+ try {
274
+ $ this ->errors = array ();
275
+ $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i );
276
+ if (count ($ this ->getErrors ()) == 0 ) {
277
+ $ matchedSchemas ++;
278
+ }
279
+ $ allErrors = array_merge ($ allErrors , array_values ($ this ->getErrors ()));
280
+ } catch (ValidationException $ e ) {
281
+ // deliberately do nothing here - validation failed, but we want to check
282
+ // other schema options in the OneOf field.
271
283
}
272
- $ allErrors = array_merge ($ allErrors , array_values ($ this ->getErrors ()));
273
284
}
274
285
if ($ matchedSchemas !== 1 ) {
275
286
$ this ->addErrors (array_merge ($ allErrors , $ startErrors ));
0 commit comments