Skip to content

Commit

Permalink
Use additional method naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
PineappleIOnic committed Jan 23, 2025
1 parent 35e9176 commit 48f32cb
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,17 @@ public function getMethods($service)
continue;
}

if (empty($method['x-appwrite']['multiplex'] ?? [])) {
if (empty($method['x-appwrite']['additional-methods'] ?? [])) {
$list[] = $this->parseMethod($methodName, $pathName, $method);
continue;
}

foreach ($method['x-appwrite']['multiplex'] as $multiplex) {
$multiplexMethod = $method;
$multiplexMethod['x-appwrite']['method'] = $multiplex['name'];
foreach ($method['x-appwrite']['additional-methods'] as $additionalMethod) {
$duplicatedMethod = $method;
$duplicatedMethod['x-appwrite']['method'] = $additionalMethod['name'];

// Update Response
$responses = $multiplexMethod['responses'];
$responses = $duplicatedMethod['responses'];
$convertedResponse = [];

foreach ($responses as $code => $desc) {
Expand All @@ -309,7 +309,7 @@ public function getMethods($service)
}

foreach ($desc['schema']['x-oneOf'] as $oneOf) {
if (!isset($oneOf['$ref']) || !str_ends_with($oneOf['$ref'], $multiplex['response'])) {
if (!isset($oneOf['$ref']) || !str_ends_with($oneOf['$ref'], $additionalMethod['response'])) {
continue;
}

Expand All @@ -320,44 +320,44 @@ public function getMethods($service)
}
}

$multiplexMethod['responses'] = $convertedResponse;
$duplicatedMethod['responses'] = $convertedResponse;

// Remove non-whitelisted parameters on body parameters, also set required.
$handleParams = function (&$params) use ($multiplex) {
if (isset($multiplex['parameters'])) {
$handleParams = function (&$params) use ($additionalMethod) {
if (isset($additionalMethod['parameters'])) {
foreach ($params as $key => $param) {
if (empty($param['in']) || $param['in'] !== 'body' || empty($param['schema']['properties'])) {
continue;
}

$whitelistedParams = $multiplex['parameters'] ?? [];
$whitelistedParams = $additionalMethod['parameters'] ?? [];

foreach ($param['schema']['properties'] as $paramName => $value) {
if (!in_array($paramName, $whitelistedParams)) {
unset($param['schema']['properties'][$paramName]);
}
}

$param['schema']['required'] = $multiplex['required'] ?? [];
$param['schema']['required'] = $additionalMethod['required'] ?? [];
$params[$key] = $param;
}
}

return;
};

$handleParams($multiplexMethod['parameters']);
$handleParams($duplicatedMethod['parameters']);

// Overwrite description and name if multiplex has one
if (!empty($multiplex['name'])) {
$multiplexMethod['summary'] = $multiplex['name'];
if (!empty($additionalMethod['name'])) {
$duplicatedMethod['summary'] = $additionalMethod['name'];
}

if (!empty($multiplex['description'])) {
$multiplexMethod['description'] = $multiplex['description'];
if (!empty($additionalMethod['description'])) {
$duplicatedMethod['description'] = $additionalMethod['description'];
}

$list[] = $this->parseMethod($methodName, $pathName, $multiplexMethod);
$list[] = $this->parseMethod($methodName, $pathName, $duplicatedMethod);
}
}
}
Expand Down

0 comments on commit 48f32cb

Please sign in to comment.