core icon indicating copy to clipboard operation
core copied to clipboard

fix(jsonld): allow @id, @context and @type on denormalization

Open soyuka opened this issue 1 year ago • 3 comments

#6225

soyuka avatar May 31 '24 09:05 soyuka

General question. I think I saw it written somewhere but I can't find it now. What is the easiest way to test a fork? like in an existing api-platform template clone, replace the /vendor/api-platform/core with the peached version to see if it works.

Anyway I think it's not working as in Symfony here isAllowedAttribute() is not called if it's not in $allowedAttributes that is set here from:

https://github.com/api-platform/core/blob/73a4c324a3fe8d7e40ed2232c1e91cd0b4731805/src/Serializer/AbstractItemNormalizer.php#L418-L443

where $allowedAttributes = []; is empty and gets filled only with items from the object && isAllowedAttribute() and in our case there are not in the object so isAllowedAttribute() is not checked.

ili101 avatar May 31 '24 15:05 ili101

Hi, the best way to test the branch is to use https://getcomposer.org/doc/05-repositories.md#vcs with the fork and the branch

soyuka avatar Jun 14 '24 07:06 soyuka

So as I said above https://github.com/api-platform/core/pull/6402#issuecomment-2142494980 this seems not to have any effect. I don't quite understand Symfony's point of isAllowedAttribute() if it's being superseded by getAllowedAttributes(). But this approach I made before works https://github.com/api-platform/core/pull/6274/. So using the same approach but instead of adding a new context option I just did what you did and added the items. branch: https://github.com/ili101/api-platform-core/tree/id (https://github.com/ili101/api-platform-core/commit/7f483074a757a395e378ff5ef8cf963b6e5a5ec1) Edit: moved to JsonLd ItemNormalizer https://github.com/ili101/api-platform-core/commit/ad132ad7ee62b8756a3f1291cfd0c73c0cfa237b

And with this it's possible to use the @id as described in the documentation while using allow_extra_attributes: false

ili101 avatar Jun 30 '24 20:06 ili101

nice, can you open a new PR to replace mine?

soyuka avatar Jul 03 '24 09:07 soyuka

superseeded by https://github.com/api-platform/core/pull/6451

soyuka avatar Jul 04 '24 15:07 soyuka