From f426cf4f6e4bae26657fa51d88a9bfe33fbe0b6c Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Thu, 13 Aug 2026 14:01:10 +0530 Subject: [PATCH] Fix the leak in the endpoint rather than in Response Coercing arrays inside output() is new behaviour in code every service and cloud inherits, and it already cost a regression: union-typed rules reached a branch that cannot resolve them and returned 500s on account reads. Endpoints building their own Documents is the shape already used by listMockNumbers, listNamespaces and listOAuth2Providers. Restore that shape in listFrameworks and leave Response untouched. Making the model authoritative everywhere is worth doing, but as its own change with a response-shape test per endpoint it alters. --- .../Modules/Sites/Http/Frameworks/XList.php | 10 ++++++++- src/Appwrite/Utopia/Response.php | 6 ------ tests/unit/Utopia/ResponseTest.php | 21 ------------------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php index e49ace4486..52ddc1d53e 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Frameworks/XList.php @@ -79,9 +79,17 @@ class XList extends Base } } + // Response models only filter nested Documents; plain arrays ship every key they carry. + $frameworks = \array_map(fn (array $framework) => new Document(\array_replace($framework, [ + 'adapters' => \array_map( + fn (array $adapter) => new Document($adapter), + $framework['adapters'] ?? [] + ), + ])), \array_values($frameworks)); + $response->dynamic(new Document([ 'total' => count($frameworks), - 'frameworks' => \array_values($frameworks) + 'frameworks' => $frameworks ]), Response::MODEL_FRAMEWORK_LIST); } } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index c5ef65ceda..aa261a320b 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -562,12 +562,6 @@ class Response extends SwooleResponse } foreach ($data[$key] as $index => $item) { - // A model-typed rule handed a raw array would otherwise ship every key it carries. - // Union types are left alone: their branch resolves a model per 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/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index 2d83240b44..e00809ce26 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -188,27 +188,6 @@ final class ResponseTest extends TestCase $this->assertArrayNotHasKey('hidden', $single); } - public function testResponseModelListsOfArrays(): void - { - $output = $this->response->output(new Document([ - 'singles' => [ - [ - 'string' => 'lorem ipsum', - 'integer' => 123, - 'boolean' => true, - 'hidden' => 'secret' - ] - ], - ]), 'lists'); - - $this->assertCount(1, $output['singles']); - - $single = $output['singles'][0]; - $this->assertArrayHasKey('string', $single); - $this->assertArrayHasKey('required', $single); - $this->assertArrayNotHasKey('hidden', $single); - } - public function testResponseModelNested(): void { $output = $this->response->output(new Document([