json-api-doc icon indicating copy to clipboard operation
json-api-doc copied to clipboard

Cannot represent resource links

Open rogerrohrbach opened this issue 4 years ago • 0 comments

  • JSON API doc version: 0.15.0
  • Python version: n/a
  • Operating System: n/a

Summary

It is not possible to serialize or deserialize resource links, i.e., a links member within a JSON API resource object.

Description

A JSON API resource object MAY contain a links member. This is a valid JSON API resource object:

{
  "type": "articles",
  "id": "1",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "links": {
    "self": "http://example.com/articles/1"
  }
}

json-api-doc will not properly deserialize a document having this object as its primary data:

import json_api_doc

doc = {
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "Rails is Omakase"
    },
    "links": {
      "self": "http://example.com/articles/1"
    }
  }
}

obj = json_api_doc.deserialize(doc)

print(obj)  # {'type': 'articles', 'id': '1', 'title': 'Rails is Omakase'}

Moreover, it is not possible to generate this document by serializing a Python object. If links is passed in data, it becomes an attribute; using the links keyword argument is inappropriate, as it creates a top-level member, outside of the primary data.

Links within a relationships member are similarly mishandled.

rogerrohrbach avatar Nov 17 '20 05:11 rogerrohrbach