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

attributes type property it is being overridden

Open tombiasz opened this issue 6 years ago • 2 comments

First of all I want to say thank you for creating such neat package 🙇

Unfortunately I found a little bug using it. As it is stated in the title, If data.attributes contains type property (data.attributes.type) it is being overridden by type in data object (data.type)

As is:

const jsonApiNormalize = require('json-api-normalize');

const input = {
    data: {
        type: 'article', // <--
        id: '1',
        attributes: {
            type: 'other type' // <--

            title: 'JSON API paints my bikeshed!',
            body: 'The shortest article. Ever.',
        },
    },
}

jsonApiNormalize(input).get(['type']);
// returns { type:"article" }

To be: Should return { type:"other type" }

Not sure how this should be resolved, because there might be situation where data.type is also needed. Maybe some special char should be introduced like $ eg $id would be equal to data.id and $type to data.type

tombiasz avatar Feb 01 '19 10:02 tombiasz

Any luck resolving this issue?

scoutkirkolson avatar Sep 09 '19 09:09 scoutkirkolson

The same error

m-alva avatar Aug 31 '20 22:08 m-alva