-
-
Notifications
You must be signed in to change notification settings - Fork 908
additional_allowed_attributes #6274
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this a symfony option?
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.
No,
allow_extra_attributes
is Symfony, andadditional_allowed_attributes
is something I added.As I can see Symfony AbstractObjectNormalizer is extended by API-Platform AbstractItemNormalizer where
getAllowedAttributes()
is overeaten. I added there a newadditional_allowed_attributes
option to allow additional attributes whenallow_extra_attributes
is set.I don't see any bulletin option to do this (maybe I missed it?) and later AbstractItemNormalizer extended again and made final so
getAllowedAttributes()
cannot be modified again by the API-Platform user.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.
Isn't
allow_extra_attributes
working?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.
allow_extra_attributes
is Symfony way of making the system throw a validation error if the API has extra attributes. It works and is needed foradditional_allowed_attributes
to have a meaning.additional_allowed_attributes
comes to solve the problem of when you need to whitelist some attributes when usingallow_extra_attributes = false
.For example, as described in https://api-platform.com/docs/core/serialization/#denormalization
When trying to do this in combination with
allow_extra_attributes = false
you will get an error that@id
is not valid as it doesn't exist on the object. to solve this you can add, in addition, the config'additional_allowed_attributes' => ['@id']
to tell the deserializer that even that extra attributes are not allowed, and the object doesn't have an@id
property, allow it anyway.Additionally, this also lets you whitelist other attributes you wish to allow while using
allow_extra_attributes = false
, for example'additional_allowed_attributes' => ['@id', '@type', 'id', '@context', 'extraParam']
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.
Okay I understand now, so you want
allow_extra_attributes
tofalse
but denormalize a JSON-LD document. I think that this should work from scratch, @dunglas any thoughts?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.
Possibly. My use case is basically I want to POST a new record
/action
(including sub-records) and then edit the response and POST it again like/action/1/submit
.So for the sub-records to work I must have the
@id
s. Additionally, for ease of use, I also like to allow the other stuff so the user will not need to remove it while resubmitting. So in my use-case with this fix I used'additional_allowed_attributes' => ['@id', '@type', 'id', '@context']
.So allowing
['@id', '@type', 'id', '@context']
out of the box or adding'additional_allowed_attributes'
dynamic option, or possibly both so it will work out of the box and be extendable works for me.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.
Appreciate it if this (
additional_allowed_attributes
) gets approved or alternatively, if you want to go with a hardcoded solution as @soyuka suggested like allowing@id
or['@id', '@type', 'id', '@context']
in src/JsonLd/Serializer/ItemNormalizer.php and allowingid
in src/JsonApi/Serializer/ItemNormalizer.php in some way.@dunglas @soyuka
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'd like to avoid a new serialization context, can you check #6402 ?