elm-jsonapi
elm-jsonapi copied to clipboard
Relationships should not require a data attribute.
I'm having trouble with the following jsonapi document.
{
"included": [
{
"type": "org",
"relationships": {
"members": {
"links": {
"related": "/api/orgs/1/members"
}
}
}
}
]
}
Decoding fails because some of the relationships do not contain a data attribute. I'm not entirely sure that this is "valid" json-api, but it seems to work with other json-api libraries.
According to the spec, the relationships must contain at least one of data, links or meta. That means the above is a valid JSON API document. If it's failing to parse, I'd consider it a bug.
It's bailing here: https://github.com/noahzgordon/elm-jsonapi/blob/master/src/JsonApi/Decode.elm#L131
I'm seeing a similar issue, where the relationships object contains an object with "data": null - which according to http://jsonapi.org/format/#document-resource-object-linkage seems to be valid (and this is generated by Django REST Framework with a JSON API module). I'm slowly working through a patch, but it's quite fundamental I think, because of https://github.com/noahzgordon/elm-jsonapi/blob/af2d14762da0f0c7b5ae54cfc4feb99617cbf8d6/src/JsonApi/Data.elm#L50
Data in a relationship can be null, so I think data : OneOrMany ResourceIdentifier has to change to perhaps data : Maybe OneOrMany ResourceIdentifier, which then has knock-on effects. If there is a better way to model the data (I'm very very new to Elm) please let me know.