diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index bdb95f4a..e2d64026 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -329,7 +329,6 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i if (isset($schema->anyOf)) { $isValid = false; $startErrors = $this->getErrors(); - $caughtException = null; foreach ($schema->anyOf as $anyOf) { $initErrors = $this->getErrors(); try { @@ -349,24 +348,21 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i } if (isset($schema->oneOf)) { - $allErrors = array(); $matchedSchemas = 0; $startErrors = $this->getErrors(); foreach ($schema->oneOf as $oneOf) { + $initErrors = $this->getErrors(); try { - $this->errors = array(); $this->checkUndefined($value, $oneOf, $path, $i); - if (count($this->getErrors()) == 0) { + if (count($this->getErrors()) == count($initErrors)) { $matchedSchemas++; } - $allErrors = array_merge($allErrors, array_values($this->getErrors())); } catch (ValidationException $e) { // deliberately do nothing here - validation failed, but we want to check // other schema options in the OneOf field. } } if ($matchedSchemas !== 1) { - $this->addErrors(array_merge($allErrors, $startErrors)); $this->addError(ConstraintError::ONE_OF(), $path); } else { $this->errors = $startErrors; diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index ff8bded3..8d78b8aa 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -79,11 +79,11 @@ public function getInvalidTests() array( 'property' => 'prop2', 'pointer' => '/prop2', - 'message' => 'Array value found, but a string is required', + 'message' => 'Array value found, but a number is required', 'constraint' => array( 'name' => 'type', 'params' => array( - 'expected' => 'a string', + 'expected' => 'a number', 'found' => 'array' ) ), @@ -92,11 +92,11 @@ public function getInvalidTests() array( 'property' => 'prop2', 'pointer' => '/prop2', - 'message' => 'Array value found, but a number is required', + 'message' => 'Array value found, but a string is required', 'constraint' => array( 'name' => 'type', 'params' => array( - 'expected' => 'a number', + 'expected' => 'a string', 'found' => 'array' ) ),