Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Platform/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function initHttp(array $services): void
switch ($option['type']) {
case 'param':
$key = substr($key, stripos($key, ':') + 1);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation']);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation'], $option['deprecated'], $option['example']);
break;
case 'injection':
$hook->inject($option['name']);
Expand Down Expand Up @@ -165,7 +165,7 @@ protected function initTasks(array $services): void
switch ($option['type']) {
case 'param':
$key = substr($key, stripos($key, ':') + 1);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation']);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation'], $option['deprecated'], $option['example']);
break;
case 'injection':
$hook->inject($option['name']);
Expand Down Expand Up @@ -222,7 +222,7 @@ protected function initWorker(array $services, string $workerName): void
switch ($option['type']) {
case 'param':
$key = substr($key, stripos($key, ':') + 1);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation']);
$hook->param($key, $option['default'], $option['validator'], $option['description'], $option['optional'], $option['injections'], $option['skipValidation'], $option['deprecated'], $option['example']);
break;
case 'injection':
$hook->inject($option['name']);
Expand Down
26 changes: 26 additions & 0 deletions tests/Platform/TestActionWithParams.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Utopia\Tests;

use Utopia\Platform\Action;
use Utopia\Validator\Boolean;
use Utopia\Validator\Range;
use Utopia\Validator\Text;

class TestActionWithParams extends Action
{
public function __construct()
{
$this->httpPath = '/with-params';
$this->httpMethod = 'GET';

$this
->param('name', '', new Text(128), 'User name.', false, example: 'John Doe')
->param('age', 0, new Range(0, 150), 'User age.', true, example: '25')
->param('active', false, new Boolean(true), 'Is active.', true, deprecated: true, example: 'true')
->inject('response')
->callback(function ($name, $age, $active, $response) {
$response->send('OK');
});
}
}
1 change: 1 addition & 0 deletions tests/Platform/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public function __construct()
$this->addAction('chunked', new TestActionChunked());
$this->addAction('redirect', new TestActionRedirect());
$this->addAction('initHook', new TestActionInit());
$this->addAction('withParams', new TestActionWithParams());
}
}
33 changes: 33 additions & 0 deletions tests/e2e/HTTPServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,37 @@ public function testHook()
$this->assertEquals('Hello World!', $result);
$this->assertEquals('', ($response1->getHeaders()['x-init'] ?? ''));
}

public function testActionParamFieldsForwardedToRoute()
{
$routes = Http::getRoutes();

$route = null;
foreach ($routes as $method => $methodRoutes) {
foreach ($methodRoutes as $r) {
if ($r->getPath() === '/with-params') {
$route = $r;
break 2;
}
}
}

$this->assertNotNull($route, 'Route /with-params should be registered');

$params = $route->getParams();

// Verify all Action::param() fields are forwarded to the Route
$actionParamKeys = ['default', 'validator', 'description', 'optional', 'injections', 'skipValidation', 'deprecated', 'example'];

foreach ($params as $name => $param) {
foreach ($actionParamKeys as $key) {
$this->assertArrayHasKey($key, $param, "Param '{$name}' is missing '{$key}' on the Route. Platform must forward all Action param fields.");
}
}

$this->assertEquals('John Doe', $params['name']['example']);
$this->assertFalse($params['name']['deprecated']);
$this->assertEquals('true', $params['active']['example']);
$this->assertTrue($params['active']['deprecated']);
}
}
Loading