Refactor path parameter detection in OpenAPI3 and Swagger2 by utilizing array flipping for improved performance and clarity in matching aliases.

This commit is contained in:
ArnabChatterjee20k
2026-05-08 14:39:26 +05:30
parent 07973dee2d
commit d303d6f807
2 changed files with 10 additions and 22 deletions
@@ -756,19 +756,13 @@ class OpenAPI3 extends Format
}
$pathAliases = [$name, ...($param['aliases'] ?? [])];
$pathAliasMap = \array_flip($pathAliases);
$isPathParam = false;
foreach ($pathAliases as $pathAlias) {
$pathNeedle = ':' . $pathAlias;
$offset = 0;
while (false !== ($position = \strpos($url, $pathNeedle, $offset))) {
$nextChar = $url[$position + \strlen($pathNeedle)] ?? '';
if ($nextChar === '' || $nextChar === '/') {
$isPathParam = true;
break 2;
}
$offset = $position + 1;
foreach (\explode('/', $url) as $segment) {
if ($segment !== '' && $segment[0] === ':' && isset($pathAliasMap[\substr($segment, 1)])) {
$isPathParam = true;
break;
}
}
@@ -723,19 +723,13 @@ class Swagger2 extends Format
}
$pathAliases = [$name, ...($param['aliases'] ?? [])];
$pathAliasMap = \array_flip($pathAliases);
$isPathParam = false;
foreach ($pathAliases as $pathAlias) {
$pathNeedle = ':' . $pathAlias;
$offset = 0;
while (false !== ($position = \strpos($url, $pathNeedle, $offset))) {
$nextChar = $url[$position + \strlen($pathNeedle)] ?? '';
if ($nextChar === '' || $nextChar === '/') {
$isPathParam = true;
break 2;
}
$offset = $position + 1;
foreach (\explode('/', $url) as $segment) {
if ($segment !== '' && $segment[0] === ':' && isset($pathAliasMap[\substr($segment, 1)])) {
$isPathParam = true;
break;
}
}