Skip to content

Allow updating nested resource on POST #1625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2018
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
33 changes: 25 additions & 8 deletions features/hydra/error.feature
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Feature: Error handling
And the JSON node "hydra:description" should exist
And the JSON node "trace" should exist

@dropSchema
Scenario: Get an error during update of an existing resource with a non-allowed update operation
When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/dummies" with body:
Expand All @@ -103,23 +104,39 @@ Feature: Error handling
And the JSON node "hydra:description" should be equal to "Update is not allowed for this operation."
And the JSON node "trace" should exist

Scenario: Get an error during update of an existing relation with a non-allowed update operation
@createSchema
Scenario: Populate database with related dummies. Check that id will be "/related_dummies/1"
Given I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/related_dummies" with body:
"""
{
"@type": "https://schema.org/Product",
"symfony": "laravel"
}
"""
Then the response status code should be 201
And the response should be in JSON
And the JSON node "@id" should be equal to "/related_dummies/1"
And the JSON node "symfony" should be equal to "laravel"

@dropSchema
Scenario: Do not get an error during update of an existing relation with a non-allowed update operation
When I add "Content-Type" header equal to "application/ld+json"
And I send a "POST" request to "/relation_embedders" with body:
"""
{
"anotherRelated": {
"@id": "/related_dummies/2",
"@id": "/related_dummies/1",
"@type": "https://schema.org/Product",
"symfony": "phalcon"
}
}
"""
Then the response status code should be 400
Then the response status code should be 201
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 "@context" should be equal to "/contexts/Error"
And the JSON node "@type" should be equal to "hydra:Error"
And the JSON node "hydra:title" should be equal to "An error occurred"
And the JSON node "hydra:description" should be equal to "Update is not allowed for this operation."
And the JSON node "trace" should exist
And the JSON node "@context" should be equal to "/contexts/RelationEmbedder"
And the JSON node "@type" should be equal to "RelationEmbedder"
And the JSON node "@id" should be equal to "/relation_embedders/1"
And the JSON node "anotherRelated.@id" should be equal to "/related_dummies/1"
And the JSON node "anotherRelated.symfony" should be equal to "phalcon"
1 change: 1 addition & 0 deletions src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ private function denormalizeRelation(string $attributeName, PropertyMetadata $pr
($propertyMetadata->isWritableLink() && \is_array($value))
) {
$context['resource_class'] = $className;
$context['api_allow_update'] = true;

return $this->serializer->denormalize($value, $className, $format, $context);
}
Expand Down