vt-elixir / ja_serializer

JSONAPI.org Serialization in Elixir.
Other
640 stars 148 forks source link

Remove relationships if they provide no information #235

Closed yogipatel closed 5 years ago

yogipatel commented 7 years ago

Addresses #232

Per the JSON-API spec,

"relationships": {
  "comments": {},
}

is not a valid format for the comments relationship. This PR adds a filter to the relationship builder that removes any relationship entry that provides no information (no data, links, or meta). As a (useful) side-effect, if the relationships key is empty, it too is omitted.

bcardarella commented 7 years ago

I would add a test for this

alanpeabody commented 7 years ago

A test would be great!

coladarci commented 7 years ago

Any updates on this? Seems like a fantastic improvement and am currently being bit by the dreaded parse error JSON::API::InvalidDocument: a relationship object MUST contain at least one of 'links', 'data', or 'meta'

yogipatel commented 7 years ago

Sorry, got lost in the noise. I'll put up some tests. Looks like the codepath is different now so might take me a couple of days.

beerlington commented 6 years ago

@yogipatel I'm trying to get some of the easier issues and PRs wrapped up before getting the next release out. If you can get a test added in the next week or so it will get added, otherwise we'll get it in after. Thanks!

pmyjavec commented 6 years ago

@beerlington, any updates on this one?

bundsol commented 6 years ago

By the way, if you make use of the following option, include: "author,comments.author" You don't get empty relationships

beerlington commented 5 years ago

Closed in favor of https://github.com/vt-elixir/ja_serializer/pull/311