From c4bdc0f9f02ebdd57156cbc033b3ffd54b06f19a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 3 Jun 2026 16:16:34 +0530 Subject: [PATCH] Add query project auth scheme to specs (#12481) --- src/Appwrite/Platform/Tasks/Specs.php | 18 ++++++++++++++++++ src/Appwrite/SDK/Method.php | 13 ++++++++++++- .../SDK/Specification/Format/OpenAPI3.php | 8 ++++++-- .../SDK/Specification/Format/Swagger2.php | 8 ++++++-- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index c8120bd017..8717ae742e 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -139,6 +139,12 @@ class Specs extends Action 'description' => 'Your project ID', 'in' => 'header', ], + 'ProjectQuery' => [ + 'type' => 'apiKey', + 'name' => 'project', + 'description' => 'Your project ID', + 'in' => 'query', + ], 'JWT' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-JWT', @@ -195,6 +201,12 @@ class Specs extends Action 'description' => 'Your project ID', 'in' => 'header', ], + 'ProjectQuery' => [ + 'type' => 'apiKey', + 'name' => 'project', + 'description' => 'Your project ID', + 'in' => 'query', + ], 'Key' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Key', @@ -263,6 +275,12 @@ class Specs extends Action 'description' => 'Your project ID', 'in' => 'header', ], + 'ProjectQuery' => [ + 'type' => 'apiKey', + 'name' => 'project', + 'description' => 'Your project ID', + 'in' => 'query', + ], 'Key' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Key', diff --git a/src/Appwrite/SDK/Method.php b/src/Appwrite/SDK/Method.php index c74406b2a6..5f6ccf9a0f 100644 --- a/src/Appwrite/SDK/Method.php +++ b/src/Appwrite/SDK/Method.php @@ -32,6 +32,7 @@ class Method * @param array $additionalParameters * @param string $desc * @param bool $public Whether this method should be rendered on the website/documentation + * @param string $projectAuth Project authentication security scheme to use in specs */ public function __construct( protected string $namespace, @@ -49,12 +50,17 @@ class Method protected array $parameters = [], protected array $additionalParameters = [], protected string $desc = '', - protected bool $public = true + protected bool $public = true, + protected string $projectAuth = 'Project' ) { $this->validateMethod($name, $namespace); $this->validateAuthTypes($auth); $this->validateDesc($description); + if (!\in_array($projectAuth, ['Project', 'ProjectQuery'], true)) { + self::$errors[] = "Error with {$this->getRouteName()} method: Invalid project auth scheme"; + } + foreach ($responses as $response) { $this->validateResponseModel($response->getModel()); $this->validateNoContent($response); @@ -223,6 +229,11 @@ class Method return $this->additionalParameters; } + public function getProjectAuth(): string + { + return $this->projectAuth; + } + public function setNamespace(string $namespace): self { $this->namespace = $namespace; diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 8d07938bc8..dfa38b0bf5 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -85,6 +85,10 @@ class OpenAPI3 extends Format $output['components']['securitySchemes']['Project']['x-appwrite'] = ['demo' => '']; } + if (isset($output['components']['securitySchemes']['ProjectQuery'])) { + $output['components']['securitySchemes']['ProjectQuery']['x-appwrite'] = ['demo' => '']; + } + if (isset($output['components']['securitySchemes']['Key'])) { $output['components']['securitySchemes']['Key']['x-appwrite'] = ['demo' => '']; } @@ -184,7 +188,7 @@ class OpenAPI3 extends Format continue; } - $methodSecurities = ['Project' => []]; + $methodSecurities = [$methodObj->getProjectAuth() => []]; foreach ($methodObj->getAuth() as $security) { if (\array_key_exists($security->value, $this->keys)) { $methodSecurities[$security->value] = []; @@ -370,7 +374,7 @@ class OpenAPI3 extends Format } if (!empty($scope)) { - $securities = ['Project' => []]; + $securities = [$sdk->getProjectAuth() => []]; foreach ($sdk->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 9265e1ec60..20b1fb9b94 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -74,6 +74,10 @@ class Swagger2 extends Format $output['securityDefinitions']['Project']['x-appwrite'] = ['demo' => '']; } + if (isset($output['securityDefinitions']['ProjectQuery'])) { + $output['securityDefinitions']['ProjectQuery']['x-appwrite'] = ['demo' => '']; + } + if (isset($output['securityDefinitions']['Key'])) { $output['securityDefinitions']['Key']['x-appwrite'] = ['demo' => '']; } @@ -184,7 +188,7 @@ class Swagger2 extends Format continue; } - $methodSecurities = ['Project' => []]; + $methodSecurities = [$methodObj->getProjectAuth() => []]; foreach ($methodObj->getAuth() as $security) { /** @var AuthType $security */ if (\array_key_exists($security->value, $this->keys)) { @@ -361,7 +365,7 @@ class Swagger2 extends Format } if (!empty($scope)) { - $securities = ['Project' => []]; + $securities = [$sdk->getProjectAuth() => []]; foreach ($sdk->getAuth() as $security) { if (\array_key_exists($security->value, $this->keys)) {