-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Be more intelligent in determining property writable/readable link. #1974
Be more intelligent in determining property writable/readable link. #1974
Conversation
I gave only a quick look but looks legit. ping @api-platform/core-team |
This looks good to me indeed. I'd see this as a bug fix (target 2.2) though. |
Ah I did mean to target 2.2. 👍 |
I'll work on the tests. |
working on finishing this one |
Wow forgot about this one - thanks! |
targeting master as discussed with @soyuka. |
thanks @bendavies @antograssiot |
Any tests added for this? |
Commit php-cs-fixer by accident? |
Yes in fact it fixes a bad behavior that is shown by the modified groups (behat functional tests). |
Hmm... I don't see any? |
@bendavies And I assume this line in your OP: * "normalization_context": {"groups": {"foo-read", "bar-read"}}, was actually meant to be: * "normalization_context": {"groups": {"foo-read"}}, ? If so, I think this ought to be merged in |
Hmm... No, this does not make sense to me. I must be misunderstanding something or is there something I've overlooked? |
Okay, I understand now. I think this is a misfeature and should be reverted. That's not how serializer groups should be interpreted. If we need more control, it should be provided at the Symfony Serializer level. |
no, i think OP was correct. |
can you explain why you think it's a misfeature? seemed like a pretty obvious bug in |
Why should the serializer group(s) used on the property have any effect on readable/writable link status? The user can use any combination of serializer groups as they see fit, and it should not change the traversal. Serializer groups should only be considered together, as a union. Determining traversability based on the specific serializer groups that happen to be on the property is unexpected behaviour. |
You're treating serializer groups as multiple possible paths of traversal, which they're not. They just mean expose / don't expose, include / don't include. |
Well, it's a long time since I looked at this so my memory might be hazy, but the link between serialiser groups and how api platform work is not a 1 to 1 here. APIP has 2 levels of "inclusion" of an attributes which are resources.
I'm happy to be wrong and the proper approach be suggested to solve my use case, of course! |
Yes, my comments are made with these points in mind.
Unfortunately, I could only suggest accepting this as a limitation. Because as I've argued above, I think this is a misfeature. If we have property-level serializer groups, it could do what you want. Yup - it's your issue at #1922 😆 |
To further illustrate: This is how I think it should be (previous behaviour): Instead of (behaviour after this PR): |
Not sure I follow, but just to add further context: {
"id":1,
"bar":{
"id":1,
"_links":{
"self":"/bar/1",
"foo":"/foo/1"
}
},
"_links":{
"self":"/foo/1"
}
} |
I also don't think I ever used this feature after it was merged. I still have my custom normalisers. |
Our circular reference handler should already do that out of the box. |
are you sure, in the case of |
as far as i can see you'd get this. which is sort of "invalid". {
"id":1,
"bar":{
"id":1,
"foo":"/foo/1",
"_links":{
"self":"/bar/1"
}
},
"_links":{
"self":"/foo/1"
}
} PR's welcome i guess :) |
by the way, i think it's still not possible to serialize the non resursive case, without this PR Foo(1) -> Bar(1) -> Foo(2)` {
"id":1,
"bar":{
"id":1,
"_links":{
"self":"/bar/1",
"another_foo":"/foo/2"
}
},
"_links":{
"self":"/foo/1"
}
} |
Yeah, I think you're right. Support for those formats is probably lacking. 😄
Hmm... I don't understand. |
I've come across an issue where I cannot prevent a property being a readable link, given sane looking serialization Group configuration.
Consider the following Resources:
Given:
Consider normalizing
$foo
.What i want (and would expect) is
Foo::bar
to bereadable: true
readableLink: true
Foo::bar:foo
to bereadable: true
readableLink: false
but what currently is returned is
Foo::bar
to bereadable: true
readableLink: true
Foo::bar:foo
to bereadable: true
readableLink: true
I need
Foo::bar:foo
readableLink: false
so the normalization does not recurse back to Foo:Foo->Bar->Foo
, it should stop atFoo->Bar
.SerializerPropertyMetadataFactory::transformLinkStatus
does not consider the groups on the property it is evaluating the link status of. I think that would be expected, and this change would give my desired outcome.