From 35714d1f5bf20ab89af805e90996dc680c74b66f Mon Sep 17 00:00:00 2001 From: rvanlaak Date: Thu, 19 Jun 2025 15:35:52 +0200 Subject: [PATCH] fix(hydra): make the docs.jsonld Link header URI relative, to match Caddy and make client responsible of matching the original requeest's protocol --- src/Hydra/State/HydraLinkProcessor.php | 2 +- src/Hydra/Tests/State/HydraLinkProcessorTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Hydra/State/HydraLinkProcessor.php b/src/Hydra/State/HydraLinkProcessor.php index 3faff4f7aaf..8a07c56d6c5 100644 --- a/src/Hydra/State/HydraLinkProcessor.php +++ b/src/Hydra/State/HydraLinkProcessor.php @@ -45,7 +45,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables = return $this->decorated->process($data, $operation, $uriVariables, $context); } - $apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL); + $apiDocUrl = $this->urlGenerator->generate('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_PATH); $linkProvider = $request->attributes->get('_api_platform_links') ?? new GenericLinkProvider(); foreach ($operation->getLinks() ?? [] as $link) { diff --git a/src/Hydra/Tests/State/HydraLinkProcessorTest.php b/src/Hydra/Tests/State/HydraLinkProcessorTest.php index b5ce10a1009..68de343e20e 100644 --- a/src/Hydra/Tests/State/HydraLinkProcessorTest.php +++ b/src/Hydra/Tests/State/HydraLinkProcessorTest.php @@ -42,7 +42,12 @@ public function testProcess(): void $context = ['request' => $request]; $decorated = $this->createMock(ProcessorInterface::class); $urlGenerator = $this->createMock(UrlGeneratorInterface::class); - $urlGenerator->expects($this->once())->method('generate')->with('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_URL)->willReturn('/docs'); + $urlGenerator + ->expects($this->once()) + ->method('generate') + ->with('api_doc', ['_format' => 'jsonld'], UrlGeneratorInterface::ABS_PATH) + ->willReturn('/docs') + ; (new HydraLinkProcessor($decorated, $urlGenerator))->process($data, $operation, [], $context); } }