Remove redundant spec platform helpers

This commit is contained in:
Chirag Aggarwal
2026-05-20 13:26:01 +05:30
parent 7c20d21fa9
commit fcb6da4c47
3 changed files with 16 additions and 35 deletions
-19
View File
@@ -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` */
@@ -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);
@@ -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);