Single resource object not supported?
It appears that resources can only be returned as arrays using the json.api_format! method, even for a single resource object, is this the intended behavior?
When I'm returning a single object, such as:
json.api_format! @account
For "data", I get something like:
{
"data": [
{
"type": "account",
"id": "1",
"links": {
"self": "/accounts/1"
}
}
]
}
The example given at http://jsonapi.org/format/ for a single resource object is
{
"data": {
"type": "articles",
"id": "1",
"attributes": {
// ... this article's attributes
},
"relationships": {
// ... this article's relationships
}
}
}
Which doesn't return "data" as an array for a single resource object. While the spec states A logical collection of resources MUST be represented as an array, even if it only contains one item or is empty. , it doesn't seem that applies for requests that target single resources.
Primary data MUST be either:
- a single resource object, a single resource identifier object, or null, for requests that target single resources
- an array of resource objects, an array of resource identifier objects, or an empty array ([]), for requests that target resource collections
@georgecheng I'm so happy someone is interested in my gem!
I assume it's quite easy to implement such a functionality, gonna fix it this weekend :palm_tree:
I haven't fixed it yet :+1: