diff --git a/src/Appwrite/SDK/Method.php b/src/Appwrite/SDK/Method.php index 4495af3e09..bbeb80595f 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -57,12 +57,12 @@ class Method } } - private function getRouteName(): string + protected function getRouteName(): string { return $this->namespace . '.' . $this->name; } - private function validateMethod(string $name, string $namespace): void + protected function validateMethod(string $name, string $namespace): void { if (\in_array($this->getRouteName(), self::$processed)) { self::$errors[] = "Error with {$this->getRouteName()} method: Method already exists in namespace {$namespace}"; @@ -71,7 +71,7 @@ class Method self::$processed[] = $this->getRouteName(); } - private function validateAuthTypes(array $authTypes): void + protected function validateAuthTypes(array $authTypes): void { foreach ($authTypes as $authType) { if (!($authType instanceof AuthType)) { @@ -80,14 +80,14 @@ class Method } } - private function validateDesc(string $desc): void + protected function validateDesc(string $desc): void { if (empty($desc)) { self::$errors[] = "Error with {$this->getRouteName()} method: Description label is empty"; return; } - $descPath = \realpath(__DIR__ . '/../../../' . $desc); + $descPath = $this->getDescriptionFilePath(); if (!\file_exists($descPath)) { self::$errors[] = "Error with {$this->getRouteName()} method: Description file not found at {$desc}"; @@ -95,7 +95,7 @@ class Method } } - private function validateResponseModel(string|array $responseModel): void + protected function validateResponseModel(string|array $responseModel): void { $response = new Response(new HttpResponse()); @@ -112,7 +112,7 @@ class Method } } - private function validateNoContent(SDKResponse $response): void + protected function validateNoContent(SDKResponse $response): void { if ($response->getCode() === 204) { if ($response->getModel() !== Response::MODEL_NONE) { @@ -136,6 +136,16 @@ class Method return $this->description; } + /** + * This method returns the absolute path to the description file returning null if the file does not exist. + * + * @return string|null + */ + public function getDescriptionFilePath(): ?string + { + return \realpath(__DIR__ . '/../../../' . $this->getDescription()) ?: null; + } + public function getAuth(): array { return $this->auth; diff --git a/src/Appwrite/Specification/Format/OpenAPI3.php b/src/Appwrite/Specification/Format/OpenAPI3.php index 02568a8ccf..bd5405539d 100644 --- a/src/Appwrite/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/Specification/Format/OpenAPI3.php @@ -148,7 +148,7 @@ class OpenAPI3 extends Format $method = array_keys($method)[0]; } - $desc = (!empty($sdk->getDescription())) ? \realpath(__DIR__ . '/../../../../' . $sdk->getDescription()) : null; + $desc = $sdk->getDescriptionFilePath(); $produces = ($sdk->getContentType())->value; $routeSecurity = $sdk->getAuth() ?? []; $sdkPlatforms = []; diff --git a/src/Appwrite/Specification/Format/Swagger2.php b/src/Appwrite/Specification/Format/Swagger2.php index 22aac47113..7277e3ab2b 100644 --- a/src/Appwrite/Specification/Format/Swagger2.php +++ b/src/Appwrite/Specification/Format/Swagger2.php @@ -144,7 +144,7 @@ class Swagger2 extends Format $method = array_keys($method)[0]; } - $desc = (!empty($sdk->getDescription())) ? \realpath(__DIR__ . '/../../../../' . $sdk->getDescription()) : null; + $desc = $sdk->getDescriptionFilePath(); $produces = ($sdk->getContentType())->value; $routeSecurity = $sdk->getAuth() ?? []; $sdkPlatforms = [];