diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 59793ebd1f..53cbced174 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -283,7 +283,8 @@ class Specs extends Action $routes, $models, $keys[$platform], - $authCounts[$platform] ?? 0 + $authCounts[$platform] ?? 0, + $platforms[$platform] ]; foreach (['swagger2', 'open-api3'] as $format) { diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index af3b5c017e..3d3d9e07bf 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -24,6 +24,7 @@ abstract class Format protected array $services; protected array $keys; protected int $authCount; + protected string $platform; protected array $params = [ 'name' => '', 'description' => '', @@ -50,7 +51,7 @@ abstract class Format ] ]; - public function __construct(App $app, array $services, array $routes, array $models, array $keys, int $authCount) + public function __construct(App $app, array $services, array $routes, array $models, array $keys, int $authCount, string $platform) { $this->app = $app; $this->services = $services; @@ -58,6 +59,7 @@ abstract class Format $this->models = $models; $this->keys = $keys; $this->authCount = $authCount; + $this->platform = $platform; } /** diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 1d70bc3af4..c3d70fa7a2 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -177,6 +177,32 @@ class OpenAPI3 extends Format /** @var Method $method */ $desc = $method->getDescriptionFilePath(); + $methodSecurities = $method->getAuth(); + $methodSdkPlatforms = []; + foreach ($methodSecurities as $value) { + switch ($value) { + case AuthType::SESSION: + $methodSdkPlatforms[] = APP_PLATFORM_CLIENT; + break; + case AuthType::JWT: + case AuthType::KEY: + $methodSdkPlatforms[] = APP_PLATFORM_SERVER; + break; + case AuthType::ADMIN: + $methodSdkPlatforms[] = APP_PLATFORM_CONSOLE; + break; + } + } + + if (empty($methodSecurities)) { + $methodSdkPlatforms[] = APP_PLATFORM_SERVER; + $methodSdkPlatforms[] = APP_PLATFORM_CLIENT; + } + + if ($this->platform !== APP_PLATFORM_CONSOLE && !\in_array($this->platform, $methodSdkPlatforms)) { + continue; + } + $methodSecurities = ['Project' => []]; foreach ($method->getAuth() as $security) { /** @var AuthType $security */ diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 9caaa9e5f8..10acca933f 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -183,6 +183,32 @@ class Swagger2 extends Format /** @var Method $method */ $desc = $method->getDescriptionFilePath(); + $methodSecurities = $method->getAuth(); + $methodSdkPlatforms = []; + foreach ($methodSecurities as $value) { + switch ($value) { + case AuthType::SESSION: + $methodSdkPlatforms[] = APP_PLATFORM_CLIENT; + break; + case AuthType::JWT: + case AuthType::KEY: + $methodSdkPlatforms[] = APP_PLATFORM_SERVER; + break; + case AuthType::ADMIN: + $methodSdkPlatforms[] = APP_PLATFORM_CONSOLE; + break; + } + } + + if (empty($methodSecurities)) { + $methodSdkPlatforms[] = APP_PLATFORM_SERVER; + $methodSdkPlatforms[] = APP_PLATFORM_CLIENT; + } + + if ($this->platform !== APP_PLATFORM_CONSOLE && !\in_array($this->platform, $methodSdkPlatforms)) { + continue; + } + $methodSecurities = ['Project' => []]; foreach ($method->getAuth() as $security) { /** @var AuthType $security */