mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Filter model-typed rules handed raw arrays
output() recursed into a rule's items only when they were already Documents, so an endpoint passing config rows straight through shipped every key on them. listFrameworks did exactly that and leaked each adapter's startCommand along with the framework-level bundleCommand, envCommand and screenshotSleep. Coerce arrays to Documents where the rule names a model, which lets the declared rules govern the output wherever the payload came from, and drop the wrapping listFrameworks needed to work around it. A union type is always a list of models, never scalars, so the array check is enough to tell a nested model from a rule like runtimes.
This commit is contained in:
1 parent
617ce5eb5f
commit
19dff5c974
3 files changed
+31
-9
No files matched your search
@@ -79,17 +79,9 @@ 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' => $frameworks
|
||||
'frameworks' => \array_values($frameworks)
|
||||
]), Response::MODEL_FRAMEWORK_LIST);
|
||||
}
|
||||
}
|
||||
@@ -562,6 +562,11 @@ 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.
|
||||
if (\is_array($item) && (\is_array($rule['type']) || self::hasModel($rule['type']))) {
|
||||
$item = new Document($item);
|
||||
}
|
||||
|
||||
if ($item instanceof Document) {
|
||||
$ruleType = null;
|
||||
|
||||
@@ -597,6 +602,10 @@ class Response extends SwooleResponse
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (\is_array($data[$key]) && (\is_array($rule['type']) || self::hasModel($rule['type']))) {
|
||||
$data[$key] = new Document($data[$key]);
|
||||
}
|
||||
|
||||
if ($data[$key] instanceof Document) {
|
||||
$data[$key] = $this->output($data[$key], $rule['type']);
|
||||
}
|
||||
|
||||
@@ -188,6 +188,27 @@ 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([
|
||||
|
||||
Reference in new issue
Block a user