active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Adjusts Deserializer relationship parsing to allow links/meta keys

Open nikz opened this issue 8 years ago • 5 comments
trafficstars

Purpose

The JSON API spec allows for the relationships key to include one of data, links or meta.

The current parsing logic for the deserialiser raises an exception unless a data key is present (this may have been changed after the code was written 🚄), which means that we're getting an exception on a valid JSON:API document 😭

Changes

  • Adjusts the document validation inside the Deserializer to allow for one of data, links, or meta as per the spec.
  • Ignores the links or meta keys when parsing the relationship into something to be used by Rails.

Caveats

It may not be the best behaviour to ignore the keys silently - however, I'm not really sure what a useful thing to do here would be. Perhaps print a warning?

Related GitHub issues

None 😺

Additional helpful information

Thanks for the 💎, and your time reviewing this folks!

nikz avatar Sep 18 '17 20:09 nikz

@beauby any objections?

bf4 avatar Sep 19 '17 04:09 bf4

@bf4 I think this still a change that's needed - is there a reason why you closed the PR? I'm not sure the test failures are related to the changes I've made but I could update to latest 0-10-stable and attempt to get them passing?

nikz avatar Nov 20 '17 18:11 nikz

@nikz Not sure how or why I closed it

bf4 avatar Nov 20 '17 21:11 bf4

@bf4 slip of the mouse! No worries at all. Is there anything you need me to do on this patch?

nikz avatar Nov 22 '17 19:11 nikz

I think I'd rather replace our deserializer with the jsonapi-deserializer. There are prs for it. See https://github.com/rails-api/active_model_serializers/pull/1928#issuecomment-298298106

bf4 avatar Nov 26 '17 17:11 bf4