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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* Deprecate `allow_plain_identifiers` option (#4167)
* Exception: Add the ability to customize multiple status codes based on the validation exception (#4017)
* GraphQL: Fix graphql fetching with Elasticsearch (#4217)
* ApiLoader: Support `_format` resolving (#4292)

## 2.6.5

Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Routing/ApiLoader.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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