mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user