Skip to content

Commit 371879b

Browse files
committed
Merge branch '2.0' into 2.1
2 parents 53944fb + f039498 commit 371879b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

features/main/relation.feature

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ Feature: Relations support
443443
}
444444
"""
445445

446-
@dropSchema
447446
Scenario: Issue #1222
448447
Given there are people having pets
449448
When I add "Content-Type" header equal to "application/ld+json"
@@ -475,3 +474,29 @@ Feature: Relations support
475474
"hydra:totalItems": 1
476475
}
477476
"""
477+
478+
@dropSchema
479+
Scenario: Issue #1547 Passing wrong argument to a relation
480+
When I add "Content-Type" header equal to "application/ld+json"
481+
And I send a "POST" request to "/relation_embedders" with body:
482+
"""
483+
{
484+
"related": "certainly not an iri"
485+
}
486+
"""
487+
Then the response status code should be 400
488+
And the response should be in JSON
489+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
490+
And the JSON node "hydra:description" should contain "Expected IRI or nested document"
491+
492+
When I add "Content-Type" header equal to "application/ld+json"
493+
And I send a "POST" request to "/relation_embedders" with body:
494+
"""
495+
{
496+
"related": 8
497+
}
498+
"""
499+
Then the response status code should be 400
500+
And the response should be in JSON
501+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
502+
And the JSON node "hydra:description" should contain "Expected IRI or nested document"

src/Serializer/AbstractItemNormalizer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ private function denormalizeRelation(string $attributeName, PropertyMetadata $pr
292292
}
293293
}
294294

295-
if (!$this->resourceClassResolver->isResourceClass($className) || $propertyMetadata->isWritableLink()) {
295+
if (
296+
!$this->resourceClassResolver->isResourceClass($className) ||
297+
($propertyMetadata->isWritableLink() && is_array($value))
298+
) {
296299
$context['resource_class'] = $className;
297300

298301
return $this->serializer->denormalize($value, $className, $format, $context);

0 commit comments

Comments
 (0)