fix: unwanted method being added to specs

This commit is contained in:
Chirag Aggarwal
2025-07-24 10:07:46 +05:30
parent 309f6ca1f7
commit 3cbded226b
4 changed files with 57 additions and 2 deletions
+2 -1
View File
@@ -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) {
+3 -1
View File
@@ -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;
}
/**
@@ -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 */
@@ -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 */