Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attributes type property it is being overridden #4

Open
tombiasz opened this issue Feb 1, 2019 · 2 comments
Open

attributes type property it is being overridden #4

tombiasz opened this issue Feb 1, 2019 · 2 comments

Comments

@tombiasz
Copy link

tombiasz commented Feb 1, 2019

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

@scoutkirkolson
Copy link

Any luck resolving this issue?

@m-alva
Copy link

m-alva commented Aug 31, 2020

The same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants