1111
1212use JsonSchema \Constraints \TypeCheck \LooseTypeCheck ;
1313use JsonSchema \Entity \JsonPointer ;
14+ use JsonSchema \Exception \ValidationException ;
1415use JsonSchema \Uri \UriResolver ;
1516
1617/**
@@ -243,11 +244,16 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
243244 if (isset ($ schema ->anyOf )) {
244245 $ isValid = false ;
245246 $ startErrors = $ this ->getErrors ();
247+ $ caughtException = null ;
246248 foreach ($ schema ->anyOf as $ anyOf ) {
247249 $ initErrors = $ this ->getErrors ();
248- $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i );
249- if ($ isValid = (count ($ this ->getErrors ()) == count ($ initErrors ))) {
250- break ;
250+ try {
251+ $ this ->checkUndefined ($ value , $ anyOf , $ path , $ i );
252+ if ($ isValid = (count ($ this ->getErrors ()) == count ($ initErrors ))) {
253+ break ;
254+ }
255+ } catch (ValidationException $ e ) {
256+ $ isValid = false ;
251257 }
252258 }
253259 if (!$ isValid ) {
@@ -262,12 +268,17 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
262268 $ matchedSchemas = 0 ;
263269 $ startErrors = $ this ->getErrors ();
264270 foreach ($ schema ->oneOf as $ oneOf ) {
265- $ this ->errors = array ();
266- $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i );
267- if (count ($ this ->getErrors ()) == 0 ) {
268- $ matchedSchemas ++;
271+ try {
272+ $ this ->errors = array ();
273+ $ this ->checkUndefined ($ value , $ oneOf , $ path , $ i );
274+ if (count ($ this ->getErrors ()) == 0 ) {
275+ $ matchedSchemas ++;
276+ }
277+ $ allErrors = array_merge ($ allErrors , array_values ($ this ->getErrors ()));
278+ } catch (ValidationException $ e ) {
279+ // deliberately do nothing here - validation failed, but we want to check
280+ // other schema options in the OneOf field.
269281 }
270- $ allErrors = array_merge ($ allErrors , array_values ($ this ->getErrors ()));
271282 }
272283 if ($ matchedSchemas !== 1 ) {
273284 $ this ->addErrors (array_merge ($ allErrors , $ startErrors ));
0 commit comments