Skip to content

Commit 319e79b

Browse files
committed
use link parameter of operation instead of header parameter of ApiResource
1 parent cfa7278 commit 319e79b

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/State/Processor/AddLinkHeaderProcessor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
5252
// We add our header here as Symfony does it only for the main Request and we want it to be done on errors (sub-request) as well
5353
$linksProvider = $request->attributes->get('_api_platform_links');
5454
if ($this->serializer && ($links = $linksProvider?->getLinks())) {
55-
$linkHeader = implode(',', array_filter([$this->serializer->serialize($links), $response->headers->get('Link')]));
56-
$response->headers->set('Link', '' === $linkHeader ? null : $linkHeader);
55+
$response->headers->set('Link', $this->serializer->serialize($links));
5756
}
5857
$this->stopwatch?->stop('api_platform.processor.add_link_header');
5958

tests/Fixtures/TestBundle/ApiResource/DeprecationHeader.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@
1616
use ApiPlatform\Metadata\ApiProperty;
1717
use ApiPlatform\Metadata\ApiResource;
1818
use ApiPlatform\Metadata\GetCollection;
19+
use Symfony\Component\WebLink\Link;
1920

2021
#[ApiResource(
21-
operations: [new GetCollection(provider: [self::class, 'provide'])],
22-
deprecationReason: 'This API is deprecated ',
23-
headers: [
24-
'deprecation' => '@1688169599',
25-
'sunset' => 'Sun, 30 Jun 2024 23:59:59 UTC',
26-
'link' => '<https://developer.example.com/deprecation>; rel="deprecation"; type="text/html"',
27-
],
22+
operations: [new GetCollection(
23+
headers: [
24+
'deprecation' => '@1688169599',
25+
'sunset' => 'Sun, 30 Jun 2024 23:59:59 UTC',
26+
],
27+
links: [
28+
new Link('deprecation', 'https://developer.example.com/deprecation'),
29+
],
30+
deprecationReason: 'This API is deprecated',
31+
provider: [self::class, 'provide'],
32+
)],
2833
)]
2934
class DeprecationHeader
3035
{

tests/Functional/DeprecationHeaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public function testDeprecationHeader(): void
3939

4040
$this->assertContains('@1688169599', $headers['deprecation']);
4141
$this->assertContains('Sun, 30 Jun 2024 23:59:59 UTC', $headers['sunset']);
42-
$this->assertStringContainsString('<https://developer.example.com/deprecation>; rel="deprecation"; type="text/html"', $headers['link'][0]);
42+
$this->assertStringContainsString('<https://developer.example.com/deprecation>; rel="deprecation"', $headers['link'][0]);
4343
}
4444
}

0 commit comments

Comments
 (0)