From de1c09fe08b1ab47909670824f2b9a3a6152858a Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Thu, 24 Sep 2026 14:42:16 +0200 Subject: [PATCH] feat(deps): support justinrainbow/json-schema 6.x Widen the version constraint to "^5.2 || ^6.0". In 6.x, the validator passes the schema through the schema storage before validating, so the custom SchemaStorage now converts array schemas to objects (mirroring the upstream implementation) and allows boolean schemas. Co-Authored-By: Claude Opus 5.5 --- composer.json | 2 +- phpstan.neon | 6 +++++- src/Validator/SchemaStorage.php | 10 +++++++++- src/Validator/Validator.php | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 3dd708bc4..e2331ea86 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require": { "php": "^8.2", "guzzlehttp/guzzle": "^7.8", - "justinrainbow/json-schema": "^5.2", + "justinrainbow/json-schema": "^5.2 || ^6.0", "caseyamcl/guzzle_retry_middleware": "^2.9" }, "require-dev": { diff --git a/phpstan.neon b/phpstan.neon index c18d408c9..84f3d4d95 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -9,4 +9,8 @@ parameters: - identifier: match.unhandled path: src/Generated/V2/Schemas/Marketplace/*.php - identifier: instanceof.alwaysTrue - path: src/Generated \ No newline at end of file + path: src/Generated + # justinrainbow/json-schema 5.x has incorrect doc-comments on the Factory constructor + - identifier: argument.type + path: src/Validator/Validator.php + reportUnmatched: false \ No newline at end of file diff --git a/src/Validator/SchemaStorage.php b/src/Validator/SchemaStorage.php index 43adda7ea..96d579052 100644 --- a/src/Validator/SchemaStorage.php +++ b/src/Validator/SchemaStorage.php @@ -4,6 +4,7 @@ namespace Mittwald\ApiClient\Validator; +use JsonSchema\Constraints\BaseConstraint; use JsonSchema\SchemaStorageInterface; use stdClass; @@ -11,12 +12,19 @@ class SchemaStorage implements SchemaStorageInterface { private array $schemas = []; + /** + * @param mixed $schema Schema; may be passed as array, despite the interface docs + */ public function addSchema($id, $schema = null): void { + if (is_array($schema)) { + $schema = BaseConstraint::arrayToObjectRecursive($schema); + } + $this->schemas[$id] = $schema; } - public function getSchema($id): object + public function getSchema($id): object|bool { return $this->schemas[$id]; } diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 1af2ed80d..9a24cb1a9 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -18,7 +18,7 @@ class Validator extends \JsonSchema\Validator public function __construct() { $schemaStorage = new SchemaStorage(); - $factory = new Factory($schemaStorage); // @phpstan-ignore argument.type (doc-comments are incorrect) + $factory = new Factory($schemaStorage); parent::__construct($factory); }