diff --git a/src/Schema/Keywords/Items.php b/src/Schema/Keywords/Items.php index 51f1708f..6d1f8475 100644 --- a/src/Schema/Keywords/Items.php +++ b/src/Schema/Keywords/Items.php @@ -12,6 +12,9 @@ use Respect\Validation\Validator; use Throwable; +use function in_array; +use function is_array; +use function is_string; use function sprintf; class Items extends BaseKeyword @@ -46,7 +49,19 @@ public function validate($data, CebeSchema $itemsSchema): void throw InvalidSchema::becauseDefensiveSchemaValidationFailed($e); } - if (! isset($this->parentSchema->type) || ($this->parentSchema->type !== 'array')) { + if ( + ! isset($this->parentSchema->type) + || ( + ( + is_string($this->parentSchema->type) + && $this->parentSchema->type !== 'array' + ) + || ( + is_array($this->parentSchema->type) + && in_array('array', $this->parentSchema->type) === false + ) + ) + ) { throw new InvalidSchema(sprintf('items MUST be present if the type is array')); }