Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: make the keyword compliant with OpenApi 3.1 #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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