From 27d31d1043aba7a256553e47ab35a15ffda78e63 Mon Sep 17 00:00:00 2001 From: Christian Foidl Date: Tue, 24 Feb 2026 10:02:13 +0100 Subject: [PATCH 1/3] chore: support json-schema ^6 Co-authored-by: Andrew Morton <696005+mortona42@users.noreply.github.com> --- composer.json | 2 +- src/HttpApiValidationTrait.php | 6 +++--- src/Validation/ValidationResult.php | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 8a0c2c6..fa3226e 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "phpcs": "phpcs -s src tests" }, "require": { - "justinrainbow/json-schema": "^5.2", + "justinrainbow/json-schema": "^5.2 || ^6", "symfony/http-foundation": "^4 || ^5 || ^6 || ^7", "wunderwerkio/jsonapi-error": "^1.0" }, diff --git a/src/HttpApiValidationTrait.php b/src/HttpApiValidationTrait.php index fbfb898..34024ba 100644 --- a/src/HttpApiValidationTrait.php +++ b/src/HttpApiValidationTrait.php @@ -24,7 +24,7 @@ trait HttpApiValidationTrait { * The data structure to validate. * @param array|object $schema * The JSON schema to validate against. - * @param int|null $checkMode + * @param int<0, 1023>|null $checkMode * The check mode to use, see \JsonSchema\Validator::CHECK_MODE_*. * * @return \Wunderwerk\HttpApiUtils\Validation\ValidationResult @@ -46,7 +46,7 @@ protected function validateDataStructure(object &$data, array|object $schema, ?i * The JSON string to validate. * @param array|object $schema * The JSON schema to validate against. - * @param int|null $checkMode + * @param int<0, 1023>|null $checkMode * The check mode to use, see \JsonSchema\Validator::CHECK_MODE_*. * * @return \Wunderwerk\HttpApiUtils\Validation\ValidationResult @@ -65,7 +65,7 @@ protected function validateJsonString(string $payload, array|object $schema, ?in * The JSON object to validate. * @param array|object $schema * The JSON schema to validate against. - * @param int|null $checkMode + * @param int<0, 1023>|null $checkMode * The check mode to use, see \JsonSchema\Validator::CHECK_MODE_*. * * @return \Wunderwerk\HttpApiUtils\Validation\ValidationResult diff --git a/src/Validation/ValidationResult.php b/src/Validation/ValidationResult.php index 7bb12a5..2ef918c 100644 --- a/src/Validation/ValidationResult.php +++ b/src/Validation/ValidationResult.php @@ -20,7 +20,7 @@ class ValidationResult { /** * Construct new validation result. * - * @param array{property: string, pointer: string, message: string, constraint: string, pattern?: string}[] $errors + * @param array{property: string, pointer: string, message: string, constraint: string|array{name: string, params: array}, pattern?: string}[] $errors * Array of validation errors. */ public function __construct( @@ -39,7 +39,7 @@ public function isValid(): bool { /** * Get the validation errors. * - * @return array{property: string, pointer: string, message: string, constraint: string, pattern?: string}[] + * @return array{property: string, pointer: string, message: string, constraint: string|array{name: string, params: array}, pattern?: string}[] * The validation errors. */ public function getErrors(): array { @@ -65,6 +65,11 @@ public function getResponse( $errors = []; foreach ($this->getErrors() as $error) { + $constraint = $error['constraint']; + if (is_array($constraint)) { + $constraint = $constraint['name']; + } + $errors[] = new JsonApiError( status: 422, code: 'validation_error', @@ -74,7 +79,7 @@ public function getResponse( 'pointer' => $error['pointer'], ], meta: [ - 'constraint' => $error['constraint'], + 'constraint' => $constraint, ], ); } From 89f6ebbb76b6a16e92fb73ede9fc55c23fd618e6 Mon Sep 17 00:00:00 2001 From: Christian Foidl Date: Tue, 24 Feb 2026 12:00:19 +0100 Subject: [PATCH 2/3] ci: migrate to blacksmith runners --- .github/workflows/main.yml | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4718b25..54fa863 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,41 +12,52 @@ env: jobs: lint_test: name: Lint & Test - runs-on: nixos + runs-on: blacksmith-4vcpu-ubuntu-2404 strategy: matrix: reqs: - symfony: "^5" - shell: "php81" + php: "8.1" - symfony: "^5" - shell: "php82" + php: "8.2" - symfony: "^5" - shell: "php83" + php: "8.3" - symfony: "^6" - shell: "php81" + php: "8.1" - symfony: "^6" - shell: "php82" + php: "8.2" - symfony: "^6" - shell: "php83" + php: "8.3" - symfony: "^7" - shell: "php82" + php: "8.2" - symfony: "^7" - shell: "php83" + php: "8.3" - symfony: "^6" - shell: "php84" + php: "8.4" - symfony: "^7" - shell: "php84" - defaults: - run: - shell: nix develop .#${{ matrix.reqs.shell }} --command bash {0} + php: "8.4" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.reqs.php }} + tools: composer + coverage: none + env: + runner: "blacksmith" + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - name: Cache Composer dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: - path: /tmp/composer-cache - key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-php${{ matrix.reqs.php }}-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-php${{ matrix.reqs.php }}- - name: Install dependencies run: >- From 700c2b5f050488e27981eeb5bc746fba2221409d Mon Sep 17 00:00:00 2001 From: Christian Foidl Date: Tue, 24 Feb 2026 12:10:39 +0100 Subject: [PATCH 3/3] fix validateArray non-array input for json-schema ^7 --- src/HttpApiValidationTrait.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/HttpApiValidationTrait.php b/src/HttpApiValidationTrait.php index 34024ba..e50d124 100644 --- a/src/HttpApiValidationTrait.php +++ b/src/HttpApiValidationTrait.php @@ -72,7 +72,9 @@ protected function validateJsonString(string $payload, array|object $schema, ?in * The validation result. */ protected function validateArray(mixed $payload, array|object $schema, ?int $checkMode = NULL) { - $data = $this->getValidator()->arrayToObjectRecursive($payload); + $data = is_array($payload) + ? $this->getValidator()->arrayToObjectRecursive($payload) + : (object) []; return $this->validateDataStructure($data, $schema, $checkMode); }