From 530e229ba69207940ac47deaaffa60c161a28f5e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 15:23:17 +0000 Subject: [PATCH 1/2] Initial plan From 4d9f918e3f03d480da0abb49db59710d1ccd4f6e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 15:29:15 +0000 Subject: [PATCH 2/2] Fix TypeError when using preg_match with integer keys in pattern properties Co-authored-by: DannyvdSluijs <618940+DannyvdSluijs@users.noreply.github.com> --- .../Constraints/ObjectConstraint.php | 2 +- tests/Constraints/PatternPropertiesTest.php | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index c2c614a9..0e1252e3 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -61,7 +61,7 @@ public function validatePatternProperties($element, ?JsonPointer $path, $pattern continue; } foreach ($element as $i => $value) { - if (preg_match($fullRegex, $i)) { + if (preg_match($fullRegex, (string) $i)) { $matches[] = $i; $this->checkUndefined($value, $schema ?: new \stdClass(), $path, $i, in_array($i, $this->appliedDefaults)); } diff --git a/tests/Constraints/PatternPropertiesTest.php b/tests/Constraints/PatternPropertiesTest.php index a4042602..ec83ccec 100644 --- a/tests/Constraints/PatternPropertiesTest.php +++ b/tests/Constraints/PatternPropertiesTest.php @@ -197,4 +197,41 @@ public function getValidTests(): \Generator ]) ]; } + + public function getValidForAssocTests(): \Generator + { + // First yield all the regular valid tests + yield from $this->getValidTests(); + + // OpenAPI-like scenario with numeric keys (HTTP status codes) + // When JSON is decoded with associative=true, numeric keys become integers + yield 'validates OpenAPI responses with numeric status codes using assoc arrays' => [ + json_encode([ + 'responses' => [ + '200' => [ + 'description' => 'OK' + ], + '404' => [ + 'description' => 'Not Found' + ] + ] + ]), + json_encode([ + 'type' => 'object', + 'properties' => [ + 'responses' => [ + 'type' => 'object', + 'patternProperties' => [ + '^[0-9]+$' => [ + 'type' => 'object', + 'properties' => [ + 'description' => ['type' => 'string'] + ] + ] + ] + ] + ] + ]) + ]; + } }