From fcb6da4c47746be1d170c4375263bd230f5788fa Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 20 May 2026 13:26:01 +0530 Subject: [PATCH] Remove redundant spec platform helpers --- src/Appwrite/SDK/Specification/Format.php | 19 ------------------- .../SDK/Specification/Format/OpenAPI3.php | 16 ++++++++-------- .../SDK/Specification/Format/Swagger2.php | 16 ++++++++-------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/Appwrite/SDK/Specification/Format.php b/src/Appwrite/SDK/Specification/Format.php index 71cb29fdd4..2bcfd4d244 100644 --- a/src/Appwrite/SDK/Specification/Format.php +++ b/src/Appwrite/SDK/Specification/Format.php @@ -514,25 +514,6 @@ abstract class Format return \array_slice($securities, 0, $authCount); } - protected function includesTargetPlatform(array $platforms): bool - { - return !empty(\array_intersect($this->targetPlatforms, $platforms)); - } - - protected function isMultiPlatformSpec(): bool - { - return \count($this->targetPlatforms) > 1; - } - - protected function getIncludedPlatforms(array $platforms): array - { - if (!$this->isMultiPlatformSpec()) { - return \array_values(\array_unique($platforms)); - } - - return \array_values(\array_intersect($this->targetPlatforms, $platforms)); - } - protected function getRequestEnumName(string $service, string $method, string $param): ?string { /* `$service` is `$namespace` */ diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 1d1185e45f..bf31f8a868 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -146,7 +146,9 @@ class OpenAPI3 extends Format 'rate-time' => $route->getLabel('abuse-time', 3600), 'rate-key' => $route->getLabel('abuse-key', 'url:{url},ip:{ip}'), 'scope' => $route->getLabel('scope', ''), - 'platforms' => $this->getIncludedPlatforms($sdkPlatforms), + 'platforms' => \count($this->targetPlatforms) > 1 + ? \array_values(\array_intersect($this->targetPlatforms, $sdkPlatforms)) + : \array_values(\array_unique($sdkPlatforms)), 'packaging' => $sdk->isPackaging(), 'public' => $sdk->isPublic(), ], @@ -172,12 +174,10 @@ class OpenAPI3 extends Format $methodSecurities = $methodObj->getAuth(); $methodSdkPlatforms = $specs->getSDKPlatformsForRouteSecurity($methodSecurities); - if (!$this->includesTargetPlatform($methodSdkPlatforms)) { + if (empty(\array_intersect($this->targetPlatforms, $methodSdkPlatforms))) { continue; } - $methodSecurities = $this->getSecurityForPlatform($methodObj->getAuth(), $this->platform); - $additionalMethod = [ 'name' => $methodObj->getMethodName(), 'namespace' => $methodObj->getNamespace(), @@ -190,11 +190,11 @@ class OpenAPI3 extends Format 'public' => $methodObj->isPublic(), ]; - if ($this->isMultiPlatformSpec()) { - $additionalMethod['platforms'] = $this->getIncludedPlatforms($methodSdkPlatforms); + if (\count($this->targetPlatforms) > 1) { + $additionalMethod['platforms'] = \array_values(\array_intersect($this->targetPlatforms, $methodSdkPlatforms)); $additionalMethod['platformSecurity'] = $this->getPlatformSecurity($methodObj->getAuth(), $methodSdkPlatforms); } else { - $additionalMethod['auth'] = $methodSecurities; + $additionalMethod['auth'] = $this->getSecurityForPlatform($methodObj->getAuth(), $this->platform); } // add deprecation only if method has it! @@ -372,7 +372,7 @@ class OpenAPI3 extends Format } } - if ($this->isMultiPlatformSpec()) { + if (\count($this->targetPlatforms) > 1) { $temp['x-appwrite']['platformSecurity'] = $this->getPlatformSecurity($sdk->getAuth(), $sdkPlatforms); } else { $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index c7c2c91824..b844c49833 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -149,7 +149,9 @@ class Swagger2 extends Format 'rate-time' => $route->getLabel('abuse-time', 3600), 'rate-key' => $route->getLabel('abuse-key', 'url:{url},ip:{ip}'), 'scope' => $route->getLabel('scope', ''), - 'platforms' => $this->getIncludedPlatforms($sdkPlatforms), + 'platforms' => \count($this->targetPlatforms) > 1 + ? \array_values(\array_intersect($this->targetPlatforms, $sdkPlatforms)) + : \array_values(\array_unique($sdkPlatforms)), 'packaging' => $sdk->isPackaging(), 'public' => $sdk->isPublic(), ], @@ -179,12 +181,10 @@ class Swagger2 extends Format $methodSecurities = $methodObj->getAuth(); $methodSdkPlatforms = $specs->getSDKPlatformsForRouteSecurity($methodSecurities); - if (!$this->includesTargetPlatform($methodSdkPlatforms)) { + if (empty(\array_intersect($this->targetPlatforms, $methodSdkPlatforms))) { continue; } - $methodSecurities = $this->getSecurityForPlatform($methodObj->getAuth(), $this->platform); - $additionalMethod = [ 'name' => $methodObj->getMethodName(), 'namespace' => $methodObj->getNamespace(), @@ -197,11 +197,11 @@ class Swagger2 extends Format 'public' => $methodObj->isPublic(), ]; - if ($this->isMultiPlatformSpec()) { - $additionalMethod['platforms'] = $this->getIncludedPlatforms($methodSdkPlatforms); + if (\count($this->targetPlatforms) > 1) { + $additionalMethod['platforms'] = \array_values(\array_intersect($this->targetPlatforms, $methodSdkPlatforms)); $additionalMethod['platformSecurity'] = $this->getPlatformSecurity($methodObj->getAuth(), $methodSdkPlatforms); } else { - $additionalMethod['auth'] = $methodSecurities; + $additionalMethod['auth'] = $this->getSecurityForPlatform($methodObj->getAuth(), $this->platform); } // add deprecation only if method has it! @@ -368,7 +368,7 @@ class Swagger2 extends Format } } - if ($this->isMultiPlatformSpec()) { + if (\count($this->targetPlatforms) > 1) { $temp['x-appwrite']['platformSecurity'] = $this->getPlatformSecurity($sdk->getAuth(), $sdkPlatforms); } else { $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount);