diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa2fe1f..577dabde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- allow items: true to pass validation ([#801](https://github.com/jsonrainbow/json-schema/pull/801)) + ### Changed - Include actual count in collection constraint errors ([#797](https://github.com/jsonrainbow/json-schema/pull/797)) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d4116654..aaa7831a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -30,31 +30,11 @@ parameters: count: 1 path: src/JsonSchema/Constraints/BaseConstraint.php - - - message: "#^Cannot access property \\$additionalItems on stdClass\\|null\\.$#" - count: 3 - path: src/JsonSchema/Constraints/CollectionConstraint.php - - - - message: "#^Cannot access property \\$items on stdClass\\|null\\.$#" - count: 6 - path: src/JsonSchema/Constraints/CollectionConstraint.php - - message: "#^Method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) has parameter \\$value with no value type specified in iterable type array\\.$#" count: 1 path: src/JsonSchema/Constraints/CollectionConstraint.php - - - message: "#^Parameter \\#1 \\$object_or_class of function property_exists expects object\\|string, stdClass\\|null given\\.$#" - count: 1 - path: src/JsonSchema/Constraints/CollectionConstraint.php - - - - message: "#^Parameter \\#2 \\$schema of method JsonSchema\\\\Constraints\\\\CollectionConstraint\\:\\:validateItems\\(\\) expects stdClass\\|null, object given\\.$#" - count: 1 - path: src/JsonSchema/Constraints/CollectionConstraint.php - - message: "#^Method JsonSchema\\\\Constraints\\\\Constraint\\:\\:checkObject\\(\\) has parameter \\$appliedDefaults with no type specified\\.$#" count: 1 diff --git a/src/JsonSchema/Constraints/CollectionConstraint.php b/src/JsonSchema/Constraints/CollectionConstraint.php index 8d346a6f..da0e7150 100644 --- a/src/JsonSchema/Constraints/CollectionConstraint.php +++ b/src/JsonSchema/Constraints/CollectionConstraint.php @@ -50,10 +50,7 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n } } - // Verify items - if (isset($schema->items)) { - $this->validateItems($value, $schema, $path, $i); - } + $this->validateItems($value, $schema, $path, $i); } /** @@ -65,6 +62,14 @@ public function check(&$value, $schema = null, ?JsonPointer $path = null, $i = n */ protected function validateItems(&$value, $schema = null, ?JsonPointer $path = null, $i = null): void { + if (\is_null($schema) || !isset($schema->items)) { + return; + } + + if ($schema->items === true) { + return; + } + if (is_object($schema->items)) { // just one type definition for the whole array foreach ($value as $k => &$v) { diff --git a/tests/Constraints/ArraysTest.php b/tests/Constraints/ArraysTest.php index bb11a091..9c63982e 100644 --- a/tests/Constraints/ArraysTest.php +++ b/tests/Constraints/ArraysTest.php @@ -271,7 +271,17 @@ public function getValidTests(): array } } }' - ] + ], + 'items: true passes validation' => [ + 'input' => << <<