diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index aa261a320b..d41392e8fb 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -562,6 +562,10 @@ class Response extends SwooleResponse } foreach ($data[$key] as $index => $item) { + if (\is_array($item) && !\is_array($rule['type']) && self::hasModel($rule['type'])) { + $item = new Document($item); + } + if ($item instanceof Document) { $ruleType = null; diff --git a/tests/e2e/Services/Sites/SitesCustomClientTest.php b/tests/e2e/Services/Sites/SitesCustomClientTest.php index b87faec691..c498ea024e 100644 --- a/tests/e2e/Services/Sites/SitesCustomClientTest.php +++ b/tests/e2e/Services/Sites/SitesCustomClientTest.php @@ -117,6 +117,28 @@ final class SitesCustomClientTest extends Scope $this->assertEquals(400, $templates['headers']['status-code']); } + public function testListTemplatesHidesInternalFields() + { + $templates = $this->client->call(Client::METHOD_GET, '/sites/templates', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 5000, + ]); + + $this->assertEquals(200, $templates['headers']['status-code']); + $this->assertGreaterThan(0, $templates['body']['total']); + + $this->assertStringNotContainsString('startCommand', (string) json_encode($templates['body'])); + $this->assertStringNotContainsString('score', (string) json_encode($templates['body'])); + + $template = $this->getTemplate('starter-for-nextjs'); + + $this->assertEquals(200, $template['headers']['status-code']); + + $this->assertStringNotContainsString('startCommand', (string) json_encode($template['body'])); + } + public function testGetTemplate() { /** diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index f57a0b44ea..c52da6c065 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -2348,6 +2348,46 @@ final class SitesCustomServerTest extends Scope $this->assertArrayHasKey('outputDirectory', $framework['adapters'][0]); } + public function testGetFrameworksHidesStartCommand(): void + { + $frameworks = $this->client->call(Client::METHOD_GET, '/sites/frameworks', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ])); + + $this->assertEquals(200, $frameworks['headers']['status-code']); + $this->assertGreaterThan(0, $frameworks['body']['total']); + + $this->assertStringNotContainsString('startCommand', (string) json_encode($frameworks['body'])); + } + + public function testCreateSiteHidesStartCommand(): void + { + $siteId = $this->setupSite([ + 'siteId' => ID::unique(), + 'name' => 'SSR site without a start command', + 'framework' => 'nextjs', + 'adapter' => 'ssr', + 'buildRuntime' => 'node-22', + 'outputDirectory' => './.next', + 'buildCommand' => 'npm run build', + 'installCommand' => 'npm install', + ]); + + $site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + $this->assertEquals(200, $site['headers']['status-code']); + + // An omitted start command stays empty; the runtime resolves its own default at boot. + $this->assertSame('', $site['body']['startCommand']); + + $this->cleanupSite($siteId); + } + public function testSiteStatic(): void { $siteId = $this->setupSite([