Skip to content

Commit 949a4d5

Browse files
fix: allow items: true to pass validation (#801)
Fixes #799
1 parent bb68276 commit 949a4d5

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
### Fixed
10+
- allow items: true to pass validation ([#801](https://github.com/jsonrainbow/json-schema/pull/801))
11+
912
### Changed
1013
- Include actual count in collection constraint errors ([#797](https://github.com/jsonrainbow/json-schema/pull/797))
1114

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,11 @@ parameters:
3030
count: 1
3131
path: src/JsonSchema/Constraints/BaseConstraint.php
3232

33-
-
34-
message: "#^Cannot access property \\$additionalItems on stdClass\\|null\\.$#"
35-
count: 3
36-
path: src/JsonSchema/Constraints/CollectionConstraint.php
37-
38-
-
39-
message: "#^Cannot access property \\$items on stdClass\\|null\\.$#"
40-
count: 6
41-
path: src/JsonSchema/Constraints/CollectionConstraint.php
42-
4333
-
4434
message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#"
4535
count: 1
4636
path: src/JsonSchema/Constraints/CollectionConstraint.php
4737

48-
-
49-
message: "#^Parameter \\#1 \\$object_or_class of function property_exists expects object\\|string, stdClass\\|null given\\.$#"
50-
count: 1
51-
path: src/JsonSchema/Constraints/CollectionConstraint.php
52-
53-
-
54-
message: "#^Parameter \\#2 \\$schema of method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) expects stdClass\\|null, object given\\.$#"
55-
count: 1
56-
path: src/JsonSchema/Constraints/CollectionConstraint.php
57-
5838
-
5939
message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has parameter \\$appliedDefaults with no type specified\\.$#"
6040
count: 1

src/JsonSchema/Constraints/CollectionConstraint.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n
5050
}
5151
}
5252

53-
// Verify items
54-
if (isset($schema->items)) {
55-
$this->validateItems($value, $schema, $path, $i);
56-
}
53+
$this->validateItems($value, $schema, $path, $i);
5754
}
5855

5956
/**
@@ -65,6 +62,14 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n
6562
*/
6663
protected function validateItems(&$value, $schema = null, ?JsonPointer $path = null, $i = null): void
6764
{
65+
if (\is_null($schema) || !isset($schema->items)) {
66+
return;
67+
}
68+
69+
if ($schema->items === true) {
70+
return;
71+
}
72+
6873
if (is_object($schema->items)) {
6974
// just one type definition for the whole array
7075
foreach ($value as $k => &$v) {

tests/Constraints/ArraysTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,17 @@ public function getValidTests(): array
271271
}
272272
}
273273
}'
274-
]
274+
],
275+
'items: true passes validation' => [
276+
'input' => <<<JSON
277+
[1, 1.2, "12"]
278+
JSON
279+
,
280+
'schema' => <<<JSON
281+
{ "type": "array", "items": true }
282+
JSON
283+
,
284+
],
275285
];
276286
}
277287
}

0 commit comments

Comments
 (0)