From bff27d297361fffcd97f016d712bbefd6cbb46da Mon Sep 17 00:00:00 2001 From: John Charman Date: Thu, 7 Nov 2024 12:13:33 +0000 Subject: [PATCH] Use devizzent/cebe-php-openapi --- composer.json | 2 +- src/Exception/InvalidOpenAPI.php | 10 ++++++++++ src/ValueObject/Partial/Schema.php | 3 ++- src/ValueObject/Valid/V30/Schema.php | 7 ++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 27a93fb..c41dca4 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ }, "require": { "php": "^8.1.0", - "cebe/php-openapi": "^1.7" + "devizzent/cebe-php-openapi": "^1.1.0" }, "require-dev": { "phpunit/phpunit": "^10.5.36", diff --git a/src/Exception/InvalidOpenAPI.php b/src/Exception/InvalidOpenAPI.php index b93d692..7b65e49 100644 --- a/src/Exception/InvalidOpenAPI.php +++ b/src/Exception/InvalidOpenAPI.php @@ -301,6 +301,16 @@ public static function invalidType(Identifier $identifier, string $type): self return new self($message); } + public static function typeArrayInWrongVersion(Identifier $identifier): self + { + $message = <<|string|null $type * @param ?self[] $allOf * @param ?self[] $anyOf * @param ?self[] $oneOf */ public function __construct( - public ?string $type = null, + public array|string|null $type = null, public ?array $allOf = null, public ?array $anyOf = null, public ?array $oneOf = null, diff --git a/src/ValueObject/Valid/V30/Schema.php b/src/ValueObject/Valid/V30/Schema.php index 73e5d29..25cb829 100644 --- a/src/ValueObject/Valid/V30/Schema.php +++ b/src/ValueObject/Valid/V30/Schema.php @@ -91,12 +91,17 @@ public function __construct( } } - private function validateType(Identifier $identifier, ?string $type): ?Type + /** @param array|string|null $type */ + private function validateType(Identifier $identifier, array|string|null $type): ?Type { if (is_null($type)) { return null; } + if (is_array($type)) { + return throw InvalidOpenAPI::typeArrayInWrongVersion($this->getIdentifier()); + } + return Type::tryFromVersion( OpenAPIVersion::Version_3_0, $type