Skip to content

Commit 417fef5

Browse files
authoredNov 8, 2024··
fix(laravel): overlaping route format (#6782)
fixes #6779
1 parent 64e3a5a commit 417fef5

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed
 

‎src/Laravel/ApiPlatformProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
13421342
// _format is read by the middleware
13431343
$uriTemplate = $operation->getRoutePrefix().str_replace('{._format}', '{_format?}', $uriTemplate);
13441344
$route = (new Route([$operation->getMethod()], $uriTemplate, [ApiPlatformController::class, '__invoke']))
1345+
->where('_format', '^\.[a-zA-Z]+')
13451346
->name($operation->getName())
13461347
->setDefaults(['_api_operation_name' => $operation->getName(), '_api_resource_class' => $operation->getClass()]);
13471348

‎src/Laravel/Tests/JsonLdTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ protected function defineEnvironment($app): void
4141
{
4242
tap($app['config'], function (Repository $config): void {
4343
$config->set('app.debug', true);
44+
$config->set('api-platform.resources', [app_path('Models'), app_path('ApiResource')]);
4445
});
4546
}
4647

@@ -337,4 +338,14 @@ public function testRelationWithGroups(): void
337338
$this->assertArrayHasKey('relation', $content);
338339
$this->assertArrayHasKey('name', $content['relation']);
339340
}
341+
342+
/**
343+
* @see https://github.com/api-platform/core/issues/6779
344+
*/
345+
public function testSimilarRoutesWithFormat(): void
346+
{
347+
$response = $this->get('/api/staff_position_histories?page=1', ['accept' => 'application/ld+json']);
348+
$response->assertStatus(200);
349+
$this->assertSame('/api/staff_position_histories', $response->json()['@id']);
350+
}
340351
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Workbench\App\ApiResource;
15+
16+
use ApiPlatform\Metadata\ApiResource;
17+
18+
#[ApiResource(provider: [self::class, 'provide'])]
19+
class Staff
20+
{
21+
public static function provide()
22+
{
23+
return [];
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Workbench\App\ApiResource;
15+
16+
use ApiPlatform\Metadata\ApiResource;
17+
18+
#[ApiResource(provider: [self::class, 'provide'])]
19+
class StaffPositionHistory
20+
{
21+
public static function provide()
22+
{
23+
return [];
24+
}
25+
}

0 commit comments

Comments
 (0)
Please sign in to comment.