diff --git a/src/JsonLd/Action/ContextAction.php b/src/JsonLd/Action/ContextAction.php index 74c144ed81b..faa3b0b67f2 100644 --- a/src/JsonLd/Action/ContextAction.php +++ b/src/JsonLd/Action/ContextAction.php @@ -32,11 +32,6 @@ */ final class ContextAction { - public const RESERVED_SHORT_NAMES = [ - 'ConstraintViolationList' => true, - 'Error' => true, - ]; - public function __construct( private readonly ContextBuilderInterface $contextBuilder, private readonly ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, @@ -90,11 +85,6 @@ private function getContext(string $shortName): ?array return ['@context' => $this->contextBuilder->getEntrypointContext()]; } - // TODO: remove this, exceptions are resources since 3.2 - if (isset(self::RESERVED_SHORT_NAMES[$shortName])) { - return ['@context' => $this->contextBuilder->getBaseContext()]; - } - foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) { $resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($resourceClass); diff --git a/src/Serializer/SerializerContextBuilder.php b/src/Serializer/SerializerContextBuilder.php index 63ee797f426..b259e6015ea 100644 --- a/src/Serializer/SerializerContextBuilder.php +++ b/src/Serializer/SerializerContextBuilder.php @@ -76,15 +76,6 @@ public function createFromRequest(Request $request, bool $normalization, ?array $context['types'] = $types; } - // TODO: remove this as uri variables are available in the SerializerProcessor but correctly parsed - if ($operation->getUriVariables()) { - $context['uri_variables'] = []; - - foreach (array_keys($operation->getUriVariables()) as $parameterName) { - $context['uri_variables'][$parameterName] = $request->attributes->get($parameterName); - } - } - if (null === $context['output'] && $this->getStateOptionsClass($operation)) { $context['force_resource_class'] = $operation->getClass(); } diff --git a/tests/Functional/JsonLd/ContextTest.php b/tests/Functional/JsonLd/ContextTest.php index 6906f979db2..873e9d43a39 100644 --- a/tests/Functional/JsonLd/ContextTest.php +++ b/tests/Functional/JsonLd/ContextTest.php @@ -121,4 +121,22 @@ public function testResourceLevelJsonLdContextAddsNamespacePrefixes(): void $this->assertSame('http://purl.org/dc/terms/', $body['@context']['dct']); $this->assertSame('dct:title', $body['@context']['title']); } + + public function testErrorContextIsResolvedThroughItsResource(): void + { + $response = self::createClient()->request('GET', '/contexts/Error'); + $this->assertResponseIsSuccessful(); + $body = $response->toArray(); + $this->assertArrayHasKey('@context', $body); + $this->assertSame('http://www.w3.org/ns/hydra/core#', $body['@context']['hydra']); + } + + public function testConstraintViolationContextIsResolvedThroughItsResource(): void + { + $response = self::createClient()->request('GET', '/contexts/ConstraintViolation'); + $this->assertResponseIsSuccessful(); + $body = $response->toArray(); + $this->assertArrayHasKey('@context', $body); + $this->assertSame('http://www.w3.org/ns/hydra/core#', $body['@context']['hydra']); + } }