Skip to content

Commit 6b35f61

Browse files
committed
Don't throw exceptions until after checking anyOf / oneOf
Fixes #393
1 parent cf8e886 commit 6b35f61

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
230230
return;
231231
}
232232

233+
$throwExceptions = $this->factory->getConfig(Constraint::CHECK_MODE_EXCEPTIONS);
234+
233235
if (isset($schema->allOf)) {
234236
$isValid = true;
235237
foreach ($schema->allOf as $allOf) {
@@ -245,13 +247,15 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
245247
if (isset($schema->anyOf)) {
246248
$isValid = false;
247249
$startErrors = $this->getErrors();
250+
$this->factory->removeConfig($throwExceptions);
248251
foreach ($schema->anyOf as $anyOf) {
249252
$initErrors = $this->getErrors();
250253
$this->checkUndefined($value, $anyOf, $path, $i);
251254
if ($isValid = (count($this->getErrors()) == count($initErrors))) {
252255
break;
253256
}
254257
}
258+
$this->factory->addConfig($throwExceptions);
255259
if (!$isValid) {
256260
$this->addError(ConstraintError::ANY_OF(), $path);
257261
} else {
@@ -263,6 +267,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
263267
$allErrors = array();
264268
$matchedSchemas = 0;
265269
$startErrors = $this->getErrors();
270+
$this->factory->removeConfig($throwExceptions);
266271
foreach ($schema->oneOf as $oneOf) {
267272
$this->errors = array();
268273
$this->checkUndefined($value, $oneOf, $path, $i);
@@ -271,6 +276,7 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
271276
}
272277
$allErrors = array_merge($allErrors, array_values($this->getErrors()));
273278
}
279+
$this->factory->addConfig($throwExceptions);
274280
if ($matchedSchemas !== 1) {
275281
$this->addErrors(array_merge($allErrors, $startErrors));
276282
$this->addError(ConstraintError::ONE_OF(), $path);

0 commit comments

Comments
 (0)