diff --git a/src/JsonSchema/Constraints/CollectionConstraint.php b/src/JsonSchema/Constraints/CollectionConstraint.php index b1dcf35c..b43baced 100644 --- a/src/JsonSchema/Constraints/CollectionConstraint.php +++ b/src/JsonSchema/Constraints/CollectionConstraint.php @@ -33,7 +33,7 @@ public function check($value, $schema = null, $path = null, $i = null) } // Verify uniqueItems - if (isset($schema->uniqueItems)) { + if (isset($schema->uniqueItems) && $schema->uniqueItems) { $unique = $value; if (is_array($value) && count($value)) { $unique = array_map(function($e) { return var_export($e, true); }, $value); diff --git a/tests/JsonSchema/Tests/Constraints/UniqueItemsTest.php b/tests/JsonSchema/Tests/Constraints/UniqueItemsTest.php index 3006bb43..4abac569 100644 --- a/tests/JsonSchema/Tests/Constraints/UniqueItemsTest.php +++ b/tests/JsonSchema/Tests/Constraints/UniqueItemsTest.php @@ -110,6 +110,49 @@ public function getValidTests() "type": "array", "uniqueItems": true }' + ), + // below equals the invalid tests, but with uniqueItems set to false + array( + '[1,2,2]', + '{ + "type":"array", + "uniqueItems": false + }' + ), + array( + '[{"a":"b"},{"a":"c"},{"a":"b"}]', + '{ + "type":"array", + "uniqueItems": false + }' + ), + array( + '[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]', + '{ + "type": "array", + "uniqueItems": false + }' + ), + array( + '[1.0, 1.00, 1]', + '{ + "type": "array", + "uniqueItems": false + }' + ), + array( + '[["foo"], ["foo"]]', + '{ + "type": "array", + "uniqueItems": false + }' + ), + array( + '[{}, [1], true, null, {}, 1]', + '{ + "type": "array", + "uniqueItems": false + }' ) ); }