-
Notifications
You must be signed in to change notification settings - Fork 20
Bugfix: links and pagination handling #23
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
This commit contains a lot of duplicated code. This will be refactored later. refs #22
Sorry for the delay, it's been a couple busy days. I'm testing now and I find ok the custom links. I just noticed that if a link has a "meta" key, the client parses it like a Meta object, but from the spec in the Links section:
So from that I think that a links member can have no meta object, but if a meta key is found, it should be treated like a link. As for #21 I can't get the validation. If I have time I'll look it deeper, but I think that what the code is doing right now is that if data is present at the same level that the links member, it tries to set the pagination links, but it does'n check if data is object or collection, so if there is data and its not a collection I get pagination links anyway. And while we're on it, it seems your intent is to silently remove pagination links in case they're not valid. Shouldn't be this also a validation error? |
Your quote from the spec is out of context. See the sentence before:
This means, if you have an object (e.g. Document) with a
The next sentence is the significant part. Every part in a links object must be a "link".
So this example is valid:
So, you are right. JsonApiClient parses the links incorrect, but links can contain a meta object. I'll fix that.
Thanks, you're right. Will be fixed.
No, if there is no |
Sorry for the quote, I was trying to be concise, but obviously did it wrong. About the last point
I mean if there is a data attribute, but data is not a collection, but a resource object, resource identifier object or null. In that case pagination links should be invalid. I agree that with no data attribute the pagination links are valid. |
In this case the pagination links should be parsed as a "normal" link too. |
In that case, I'm ok with just the fixes mentioned before. |
Pagination links will now parsed, if the relationship "data" attribute contains a identifier collection. I'm now working on the "meta" objects in links which won't be so trivial. 😃 I need the parent object inside |
I've made the changes but spotted another problem: A link object can't be empty by spec, but JsonApiClient allows this atm. I could add more I'm thinking about introducing a new |
👍 |
This PR covers #21 and #22. The following changes were made:
DocumentLink
,ErrorLink
andRelationshipLink
allows every custom links as URL or objectlinks
will be parsed asLink
and could contain URLs, other link objects or a meta object.string
ornull
) will parse asstring
orLink
object, if the parentRelationship
object doesn't have a "data" attribute.@fcastillo-es Can you confirm this changes will fix the two issues?
Note: I'm not finished yet. I'm now working on tests and refactoring for reaching 💯% code coverage again.