Skip to content

Commit 8abfcaa

Browse files
committed
Merge pull request #202 from dicexq/master
Fix CollectionConstraint to allow uniqueItems to be false
2 parents 7c78776 + 52d7567 commit 8abfcaa

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/JsonSchema/Constraints/CollectionConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function check($value, $schema = null, $path = null, $i = null)
3333
}
3434

3535
// Verify uniqueItems
36-
if (isset($schema->uniqueItems)) {
36+
if (isset($schema->uniqueItems) && $schema->uniqueItems) {
3737
$unique = $value;
3838
if (is_array($value) && count($value)) {
3939
$unique = array_map(function($e) { return var_export($e, true); }, $value);

tests/JsonSchema/Tests/Constraints/UniqueItemsTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,49 @@ public function getValidTests()
110110
"type": "array",
111111
"uniqueItems": true
112112
}'
113+
),
114+
// below equals the invalid tests, but with uniqueItems set to false
115+
array(
116+
'[1,2,2]',
117+
'{
118+
"type":"array",
119+
"uniqueItems": false
120+
}'
121+
),
122+
array(
123+
'[{"a":"b"},{"a":"c"},{"a":"b"}]',
124+
'{
125+
"type":"array",
126+
"uniqueItems": false
127+
}'
128+
),
129+
array(
130+
'[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : true}}}]',
131+
'{
132+
"type": "array",
133+
"uniqueItems": false
134+
}'
135+
),
136+
array(
137+
'[1.0, 1.00, 1]',
138+
'{
139+
"type": "array",
140+
"uniqueItems": false
141+
}'
142+
),
143+
array(
144+
'[["foo"], ["foo"]]',
145+
'{
146+
"type": "array",
147+
"uniqueItems": false
148+
}'
149+
),
150+
array(
151+
'[{}, [1], true, null, {}, 1]',
152+
'{
153+
"type": "array",
154+
"uniqueItems": false
155+
}'
113156
)
114157
);
115158
}

0 commit comments

Comments
 (0)