From 0404e26fb1312073bf84c3ab6c66c0752d67daee Mon Sep 17 00:00:00 2001
From: philippe PICHET
Date: Mon, 16 Dec 2024 17:20:55 +0100
Subject: [PATCH] Feat: make the keyword compliant with OpenApi 3.1
---
src/Schema/Keywords/Items.php | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
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'));
}