mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Enhance URL parameter handling in OpenAPI3 and Swagger2 formats to support aliases for path parameters.
This commit is contained in:
@@ -755,7 +755,16 @@ class OpenAPI3 extends Format
|
||||
$node['schema']['default'] = $param['default'];
|
||||
}
|
||||
|
||||
if (false !== \strpos($url, ':' . $name)) { // Param is in URL path
|
||||
$pathAliases = [$name, ...($param['aliases'] ?? [])];
|
||||
$isPathParam = false;
|
||||
foreach ($pathAliases as $pathAlias) {
|
||||
if (false !== \strpos($url, ':' . $pathAlias)) {
|
||||
$isPathParam = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isPathParam) { // Param is in URL path (directly or through alias)
|
||||
$node['in'] = 'path';
|
||||
$temp['parameters'][] = $node;
|
||||
} elseif ($route->getMethod() == 'GET') { // Param is in query
|
||||
@@ -796,7 +805,9 @@ class OpenAPI3 extends Format
|
||||
}
|
||||
}
|
||||
|
||||
$url = \str_replace(':' . $name, '{' . $name . '}', $url);
|
||||
foreach ($pathAliases as $pathAlias) {
|
||||
$url = \str_replace(':' . $pathAlias, '{' . $name . '}', $url);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($bodyRequired)) {
|
||||
|
||||
@@ -722,7 +722,16 @@ class Swagger2 extends Format
|
||||
$node['default'] = $param['default'];
|
||||
}
|
||||
|
||||
if (\str_contains($url, ':' . $name)) { // Param is in URL path
|
||||
$pathAliases = [$name, ...($param['aliases'] ?? [])];
|
||||
$isPathParam = false;
|
||||
foreach ($pathAliases as $pathAlias) {
|
||||
if (\str_contains($url, ':' . $pathAlias)) {
|
||||
$isPathParam = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isPathParam) { // Param is in URL path (directly or through alias)
|
||||
$node['in'] = 'path';
|
||||
$temp['parameters'][] = $node;
|
||||
} elseif ($route->getMethod() == 'GET') { // Param is in query
|
||||
@@ -767,7 +776,9 @@ class Swagger2 extends Format
|
||||
}
|
||||
}
|
||||
|
||||
$url = \str_replace(':' . $name, '{' . $name . '}', $url);
|
||||
foreach ($pathAliases as $pathAlias) {
|
||||
$url = \str_replace(':' . $pathAlias, '{' . $name . '}', $url);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($bodyRequired)) {
|
||||
|
||||
Reference in New Issue
Block a user