Skip to content

Commit 27e396c

Browse files
bighappyfaceJustTSK
authored andcommitted
Add variable path to error output
2 parents 7c78776 + 52d7567 commit 27e396c

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-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);

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ protected function validateCommonProperties($value, $schema = null, $path = null
121121
// Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
122122
foreach ($schema->required as $required) {
123123
if (!property_exists($value, $required)) {
124+
<<<<<<< HEAD
124125
$this->addError($required, "The property " . $required . " is required", 'required');
126+
=======
127+
$this->addError((!$path) ? $required : "$path.$required", "The property " . $required . " is required", 'required');
128+
>>>>>>> 9bda789... add variable path
125129
}
126130
}
127131
} else if (isset($schema->required) && !is_array($schema->required)) {

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)