Skip to content

Commit

Permalink
Feat: make the keyword compliant with OpenApi 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
p-pichet committed Dec 16, 2024
1 parent a665e22 commit 0404e26
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Schema/Keywords/Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
}

Expand Down

0 comments on commit 0404e26

Please sign in to comment.