Skip to content

Commit

Permalink
Merge 40175d0 into cd198d2
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-bhs committed May 25, 2021
2 parents cd198d2 + 40175d0 commit 036314a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -41,6 +41,7 @@
* Symfony: Add tests with Symfony Uuid (#4230)
* OpenAPI: Allow to set extensionProperties with YAML schema definition (#4228)
* GraphQL: Fix `FieldsBuilder` not fully unwrapping nested types before deciding if a resolver is needed (#4251)
* ApiLoader: Support `_format` resolving (#4292)

## 2.6.4

Expand Down
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' => $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' => $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' => $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' => $extraDefaults['_format'] ?? null,
'_api_resource_class' => $resourceClass,
'_api_subresource_operation_name' => $operationName,
'_api_subresource_context' => $context,
Expand Down

0 comments on commit 036314a

Please sign in to comment.