Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/ObjectConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
37 changes: 37 additions & 0 deletions tests/Constraints/PatternPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
]
]
]
]
]
])
];
}
}
Loading