-
-
Notifications
You must be signed in to change notification settings - Fork 917
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
Conversation
5244bea
to
966a5eb
Compare
features/hydra/error.feature
Outdated
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" | ||
|
||
When I add "Content-Type" header equal to "application/ld+json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be split in several scenarios (a scenario should not have several When
steps).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the first lines are to check that the insertion is correct (mainly that the @id
is /related_dummies/1
). I can change the line 109 from When
to Given
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it should follow the format:
Given ...
And ...
When ...
And ...
Then ...
And ...
You can also split it in two scenarios.
Then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dunglas done
@@ -98,7 +98,9 @@ public function denormalize($data, $class, $format = null, array $context = []) | |||
{ | |||
// Avoid issues with proxies if we populated the object | |||
if (isset($data['@id']) && !isset($context[self::OBJECT_TO_POPULATE])) { | |||
if (isset($context['api_allow_update']) && true !== $context['api_allow_update']) { | |||
if (isset($context['api_allow_update']) && true !== $context['api_allow_update'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about if (!($context['api_allow_update'] ?? false) && !($context['api_resource_is_relation'] ?? false))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean if (!($context['api_allow_update'] ?? true) ...
because now true is the default value for api_allow_update
(another way of saying is that an unset api_allow_update wont go if the if
).
The only difference here is if the value is set but not boolean, but that "should" not append (except if a user set it manually in the serialization context).
I like it but can maybe be hard to read, but why not.
As a matter of fact, api_allow_update
is always set in the SerializerContextBuilder
so I'm wondering if someone can denormalize an item without going through the context builder ?
If no, the code can be true !== $context['api_allow_update']
(but it may be safer to keep the isset
check.
@@ -297,6 +297,7 @@ private function denormalizeRelation(string $attributeName, PropertyMetadata $pr | |||
($propertyMetadata->isWritableLink() && \is_array($value)) | |||
) { | |||
$context['resource_class'] = $className; | |||
$context['api_resource_is_relation'] = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be easier to just set api_allow_update
to true for the subcontext in this case instead of introducing a new flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently it works, and probably fixes the src/Serializer/ItemNormalizer.php
that triggers the same error that I missed, I will do this.
e5376f4
to
a378c76
Compare
features/hydra/error.feature
Outdated
@@ -103,23 +103,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 | |||
@dropSchema |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this one, but be sure to add @dropSchema
on the last scenario to cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dunglas I missed the fact that @dropSchema
is AfterScenario
.
I took the liberty of adding a new @recreateSchema
that drop and create the schema, because I don't think relying on what did appear on the previous scenario is a good think. (mainly because someone may add another scenario between.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if I agree that it's cleaner, the problem with recreating the schema often is that is slow down all our builds...
If someone add another scenario between, it's his build that will fail 😄. His responsibility.
Would you mind to just use create/drop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fe5c7df
to
10b01ce
Compare
10b01ce
to
99bc0b0
Compare
c76005b
to
7f58508
Compare
Thanks @jdeniau |
Allow updating nested resource on POST
Allow updating nested resource on POST