Address Comments

This commit is contained in:
Bradley Schofield 2025-01-15 16:17:35 +09:00
parent 1691910023
commit 48bf8001ae
2 changed files with 33 additions and 27 deletions

View file

@ -8,7 +8,7 @@ use Swoole\Http\Response as HttpResponse;
class Method
{
public static array $knownMethods = [];
public static array $processed = [];
public static array $errors = [];
@ -53,8 +53,6 @@ class Method
foreach ($responses as $response) {
/** @var SDKResponse $response */
$this->validateResponseModel($response->getModel());
// No content check
$this->validateNoContent($response);
}
}
@ -66,11 +64,11 @@ class Method
private function validateMethod(string $name, string $namespace): void
{
if (\in_array($this->getRouteName(), self::$knownMethods)) {
if (\in_array($this->getRouteName(), self::$processed)) {
self::$errors[] = "Error with {$this->getRouteName()} method: Method already exists in namespace {$namespace}";
}
self::$knownMethods[] = $this->getRouteName();
self::$processed[] = $this->getRouteName();
}
private function validateAuthTypes(array $authTypes): void
@ -101,22 +99,16 @@ class Method
{
$response = new Response(new HttpResponse());
if (\is_array($responseModel)) {
foreach ($responseModel as $model) {
try {
$response->getModel($model);
} catch (\Exception $e) {
self::$errors[] = "Error with {$this->getRouteName()} method: Invalid response model, make sure the model has been defined in Response.php";
}
}
return;
if (!\is_array($responseModel)) {
$responseModel = [$responseModel];
}
try {
$response->getModel($responseModel);
} catch (\Exception $e) {
self::$errors[] = "Error with {$this->getRouteName()} method: Invalid response model, make sure the model has been defined in Response.php";
foreach ($responseModel as $model) {
try {
$response->getModel($model);
} catch (\Exception $e) {
self::$errors[] = "Error with {$this->getRouteName()} method: Invalid response model, make sure the model has been defined in Response.php";
}
}
}
@ -150,7 +142,7 @@ class Method
}
/**
* @return Array<SDKResponse>
* @return array<SDKResponse>
*/
public function getResponses(): array
{
@ -223,7 +215,7 @@ class Method
}
/**
* @param Array<SDKResponse> $responses
* @param array<SDKResponse> $responses
*/
public function setResponses(array $responses): self
{

View file

@ -28,15 +28,29 @@ class Request extends UtopiaRequest
$parameters = parent::getParams();
if ($this->hasFilters() && self::hasRoute()) {
$method = self::getRoute()->getLabel('sdk', null);
/** @var \Appwrite\SDK\Method $method */
$methods = self::getRoute()->getLabel('sdk', null);
if (empty($method)) {
$endpointIdentifier = 'unknown.unknown';
} else {
$endpointIdentifier = $method->getNamespace() . '.' . $method->getMethodName();
if (!\is_array($methods)) {
$methods = [$methods];
}
$params = [];
foreach ($methods as $method) {
/** @var \Appwrite\SDK\Method $method */
if (empty($method)) {
$endpointIdentifier = 'unknown.unknown';
} else {
$endpointIdentifier = $method->getNamespace() . '.' . $method->getMethodName();
}
$params += $method->getParameters();
}
$parameters = array_filter($parameters, function ($key) use ($params) {
return array_key_exists($key, $params);
}, \ARRAY_FILTER_USE_KEY);
foreach ($this->getFilters() as $filter) {
$parameters = $filter->parse($parameters, $endpointIdentifier);
}