diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index 94956dfd..889e4ecb 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -82,7 +82,7 @@ public function addErrors(array $errors) */ public function getErrors() { - return array_unique($this->errors, SORT_REGULAR); + return $this->errors; } /** diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index 02feaca6..70d4bfbf 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -40,6 +40,6 @@ public function check($value, $schema = null, $path = null, $i = null) $validator = new Schema($this->checkMode, $this->uriRetriever); $validator->check($value, $schema); - $this->addErrors($validator->getErrors()); + $this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR)); } } diff --git a/tests/JsonSchema/Tests/Constraints/OfPropertiesTest.php b/tests/JsonSchema/Tests/Constraints/OfPropertiesTest.php index f8ecd05e..b06628d3 100644 --- a/tests/JsonSchema/Tests/Constraints/OfPropertiesTest.php +++ b/tests/JsonSchema/Tests/Constraints/OfPropertiesTest.php @@ -88,6 +88,121 @@ public function getInvalidTests() ), ), ), + array( + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "oneOf": [ + { + "type": "string", + "pattern": "^[a-z]*$" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" + } + ] + } + } + }' + ), + array( + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "string", + "pattern": "^[A-Z]*$" + } + ] + } + } + }' + ), + array( + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" + } + ] + } + } + }' + ), + array( + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" + } + ] + } + } + }' + ), + array( + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "string", + "pattern": "^[a-z]*$" + }, + { + "type": "string", + "pattern": "^[A-Z]*$" + } + ] + } + } + }' + ), + array( + '{"prop1": [1,2]}', + '{ + "type": "object", + "properties": { + "prop1": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "string" + }, + { + "type": "string" + } + ] + } + } + }' + ) ); } }