Skip to content

Commit

Permalink
fix: support _format reading
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedebn authored and ahmed-bhs committed May 25, 2021
1 parent cd198d2 commit 515e22f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Routing/ApiLoader.php
Expand Up @@ -128,7 +128,7 @@ public function load($data, $type = null): RouteCollection
$operation['path'],
[
'_controller' => $controller,
'_format' => null,
'_format' => !empty($operation['defaults']['_format']) ? $operation['defaults']['_format'] : null,
'_stateless' => $operation['stateless'] ?? $resourceMetadata->getAttribute('stateless'),
'_api_resource_class' => $operation['resource_class'],
'_api_identifiers' => $operation['identifiers'],
Expand Down Expand Up @@ -241,7 +241,7 @@ private function addRoute(RouteCollection $routeCollection, string $resourceClas
$path,
[
'_controller' => $controller,
'_format' => null,
'_format' => !empty($operation['defaults']['_format']) ? $operation['defaults']['_format'] : null,
'_stateless' => $operation['stateless'],
'_api_resource_class' => $resourceClass,
'_api_identifiers' => $operation['identifiers'],
Expand Down
8 changes: 4 additions & 4 deletions tests/Bridge/Symfony/Routing/ApiLoaderTest.php
Expand Up @@ -60,7 +60,7 @@ public function testApiLoader()
]);
//custom operations
$resourceMetadata = $resourceMetadata->withCollectionOperations([
'my_op' => ['method' => 'GET', 'controller' => 'some.service.name', 'requirements' => ['_format' => 'a valid format'], 'defaults' => ['my_default' => 'default_value'], 'condition' => "request.headers.get('User-Agent') matches '/firefox/i'", 'stateless' => null], //with controller
'my_op' => ['method' => 'GET', 'controller' => 'some.service.name', 'requirements' => ['_format' => 'a valid format'], 'defaults' => ['my_default' => 'default_value', '_format' => 'a valid format'], 'condition' => "request.headers.get('User-Agent') matches '/firefox/i'", 'stateless' => null], //with controller
'my_second_op' => ['method' => 'POST', 'options' => ['option' => 'option_value'], 'host' => '{subdomain}.api-platform.com', 'schemes' => ['https'], 'stateless' => null], //without controller, takes the default one
'my_path_op' => ['method' => 'GET', 'path' => 'some/custom/path', 'stateless' => null], //custom path
'my_stateless_op' => ['method' => 'GET', 'stateless' => true],
Expand All @@ -87,7 +87,7 @@ public function testApiLoader()
);

$this->assertEquals(
$this->getRoute('/dummies.{_format}', 'some.service.name', DummyEntity::class, 'my_op', ['GET'], true, ['_format' => 'a valid format'], ['my_default' => 'default_value', '_stateless' => null], [], '', [], "request.headers.get('User-Agent') matches '/firefox/i'"),
$this->getRoute('/dummies.{_format}', 'some.service.name', DummyEntity::class, 'my_op', ['GET'], true, ['_format' => 'a valid format'], ['my_default' => 'default_value', '_format' => 'a valid format', '_stateless' => null], [], '', [], "request.headers.get('User-Agent') matches '/firefox/i'"),
$routeCollection->get('api_dummies_my_op_collection')
);

Expand Down Expand Up @@ -318,7 +318,7 @@ private function getRoute(string $path, string $controller, string $resourceClas
$path,
[
'_controller' => $controller,
'_format' => null,
'_format' => !empty($extraDefaults['_format']) ? $extraDefaults['_format'] : null,
'_api_resource_class' => $resourceClass,
'_api_identifiers' => ['id'],
'_api_has_composite_identifier' => false,
Expand All @@ -339,7 +339,7 @@ private function getSubresourceRoute(string $path, string $controller, string $r
$path,
[
'_controller' => $controller,
'_format' => null,
'_format' => !empty($extraDefaults['_format']) ? $extraDefaults['_format'] : null,
'_api_resource_class' => $resourceClass,
'_api_subresource_operation_name' => $operationName,
'_api_subresource_context' => $context,
Expand Down

0 comments on commit 515e22f

Please sign in to comment.