From 2cd91f509be68b9e1c5d4555e6b6f6933e7f5621 Mon Sep 17 00:00:00 2001 From: My Name Date: Sun, 5 Apr 2026 18:23:58 -0400 Subject: [PATCH 1/2] fix: make variableId optional in createProjectVariable endpoint --- .../Project/Http/Project/Variables/Create.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index acc39bb68d..2430c16434 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -43,7 +43,7 @@ class Create extends Base namespace: 'project', group: 'variables', name: 'createVariable', - description: <<param('variableId', '', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', false, ['dbForProject']) - ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.') + ->param('variableId', 'unique()', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true, ['dbForProject']) + ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: '.Database::LENGTH_KEY.' chars.') ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.') - ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only projects can read them during build and runtime.', true) + ->param('secret', true, new Boolean, 'Secret variables can be updated or deleted, but only projects can read them during build and runtime.', true) ->inject('response') ->inject('queueForEvents') ->inject('dbForProject') @@ -95,7 +95,7 @@ class Create extends Base foreach (['functions', 'sites'] as $collection) { $dbForProject->updateDocuments($collection, new Document([ - 'live' => false + 'live' => false, ])); } From 8bfa6591200e1e5450b69c2667636bfc529bf002 Mon Sep 17 00:00:00 2001 From: My Name Date: Wed, 8 Apr 2026 15:18:13 -0400 Subject: [PATCH 2/2] test: add test case for createProjectVariable without variableId --- .../Project/Http/Project/Variables/Create.php | 10 +++++----- .../Projects/ProjectsConsoleClientTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php index f94ac8ab8a..7b6dc67b4f 100644 --- a/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php +++ b/src/Appwrite/Platform/Modules/Project/Http/Project/Variables/Create.php @@ -42,7 +42,7 @@ class Create extends Action namespace: 'project', group: 'variables', name: 'createVariable', - description: <<<'EOT' + description: <<param('variableId', 'unique()', fn (Database $dbForProject) => new CustomId(false, $dbForProject->getAdapter()->getMaxUIDLength()), 'Variable ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true, ['dbForProject']) - ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: '.Database::LENGTH_KEY.' chars.') + ->param('key', null, new Text(Database::LENGTH_KEY), 'Variable key. Max length: ' . Database::LENGTH_KEY . ' chars.') ->param('value', null, new Text(8192, 0), 'Variable value. Max length: 8192 chars.') - ->param('secret', true, new Boolean, 'Secret variables can be updated or deleted, but only projects can read them during build and runtime.', true) + ->param('secret', true, new Boolean(), 'Secret variables can be updated or deleted, but only projects can read them during build and runtime.', true) ->inject('response') ->inject('queueForEvents') ->inject('dbForProject') @@ -94,7 +94,7 @@ class Create extends Action foreach (['functions', 'sites'] as $collection) { $dbForProject->updateDocuments($collection, new Document([ - 'live' => false, + 'live' => false ])); } diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index e0f94b64cc..0bb78e7cb8 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -4771,6 +4771,22 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals('APP_TEST_CREATE_1', $variable['body']['key']); $this->assertEmpty($variable['body']['value']); + // test for variable without variableId (auto-generated) + $variable = $this->client->call(Client::METHOD_POST, '/project/variables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $data['projectId'], + 'x-appwrite-mode' => 'admin', + ], $this->getHeaders()), [ + 'key' => 'APP_TEST_CREATE_AUTO_ID', + 'value' => 'AUTOIDVALUE', + 'secret' => false + ]); + + $this->assertEquals(201, $variable['headers']['status-code']); + $this->assertNotEmpty($variable['body']['$id']); + $this->assertEquals('APP_TEST_CREATE_AUTO_ID', $variable['body']['key']); + $this->assertEquals('AUTOIDVALUE', $variable['body']['value']); + /** * Test for FAILURE */