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

Handling of null data

Open TeamNautilus opened this issue 5 years ago • 0 comments

As stated in the JSON API specs a resource linkage object may have these values:

Resource linkage MUST be represented as one of the following:

    null for empty to-one relationships.
    an empty array ([]) for empty to-many relationships.
    a single resource identifier object for non-empty to-one relationships.
    an array of resource identifier objects for non-empty to-many relationships.

https://jsonapi.org/format/#document-resource-object-linkage

After the json-api-vanilla parsing is return an Object instead.

To reproduce:

  • Change the example.json:84 from "data": { "type": "people", "id": "9" } to "data": null

  • Add the following test:

it "should handle null data" do
   expect(doc.data.first.comments.last.author).to be_nil
end

Result:

     expected: nil
     got: #<Object:0x0000557bbcd4bd08>

We have noticed the fallback creation of an object here:

ref = ref || Object.new

Removing that line make all specs green but maybe it will results in other "untested" issues.

TeamNautilus avatar Jun 30 '20 14:06 TeamNautilus