Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions features/main/relation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,28 @@ Feature: Relations support
"related": null
}
"""

Scenario: Issue #1547 Passing wrong argument to a relation
When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/relation_embedders" with body:
"""
{
"related": "certainly not an iri"
}
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON node "hydra:description" should contain "Expected IRI or nested document"

When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/relation_embedders" with body:
"""
{
"related": 8
}
"""
Then the response status code should be 400
And the response should be in JSON
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
And the JSON node "hydra:description" should contain "Expected IRI or nested document"
5 changes: 4 additions & 1 deletion src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ private function denormalizeRelation(string $attributeName, PropertyMetadata $pr
}
}

if (!$this->resourceClassResolver->isResourceClass($className) || $propertyMetadata->isWritableLink()) {
if (
!$this->resourceClassResolver->isResourceClass($className) ||
($propertyMetadata->isWritableLink() && is_array($value))
) {
return $this->serializer->denormalize($value, $className, $format, $this->createRelationSerializationContext($className, $context));
}

Expand Down