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.
This commit is contained in:
harsh mahajan committed 2026-08-13 14:01:10 +05:30
1 parent 37e275f4c4
commit f426cf4f6e
3 files changed
+9 -28

No files matched your search

@@ -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);
}
}
-6
View File
@@ -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;
-21
View File
@@ -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([