Skip to content

Commit bf1093b

Browse files
committed
fix: wrong resource iri
1 parent 66a49fd commit bf1093b

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

features/main/standard_put.feature

+14
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ Feature: Spec-compliant PUT support
6666
"""
6767
Then the response status code should be 400
6868

69+
Scenario: Fails to create a new resource when the JSON-LD @id doesn't match the URI
70+
When I add "Content-Type" header equal to "application/ld+json"
71+
And I send a "PUT" request to "/standard_puts/7" with body:
72+
"""
73+
{
74+
"@id": "/standard_puts/6",
75+
"@context": "/contexts/StandardPut",
76+
"@type": "StandardPut",
77+
"foo": "a",
78+
"bar": "b"
79+
}
80+
"""
81+
Then the response status code should be 400
82+
6983
Scenario: Replace an existing resource
7084
When I add "Content-Type" header equal to "application/ld+json"
7185
And I send a "PUT" request to "/standard_puts/5" with body:

src/JsonLd/Serializer/ItemNormalizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ final class ItemNormalizer extends AbstractItemNormalizer
4949
use JsonLdContextTrait;
5050

5151
public const FORMAT = 'jsonld';
52-
public const JSONLD_KEYWORDS = [
52+
private const JSONLD_KEYWORDS = [
5353
'@context',
5454
'@direction',
5555
'@graph',

src/Symfony/Routing/IriConverter.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
7878
throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
7979
}
8080

81-
if ($operation && $operation->getClass() !== $parameters['_api_resource_class']) {
81+
foreach ($context['uri_variables'] ?? [] as $key => $value) {
82+
if (!isset($parameters[$key]) || $parameters[$key] !== (string) $value) {
83+
throw new InvalidArgumentException(sprintf('The iri "%s" does not reference the correct resource.', $iri));
84+
}
85+
}
86+
87+
if ($operation && is_a($operation->getClass(), $parameters['_api_resource_class'], true)) {
8288
throw new InvalidArgumentException(sprintf('The iri "%s" does not reference the correct resource.', $iri));
8389
}
8490

0 commit comments

Comments
 (0)