Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions tests/Constraints/OfPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
),
Expand All @@ -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'
)
),
Expand Down