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

Empty relationships should have data key with value null #38

Closed
JakeDluhy opened this issue Dec 7, 2017 · 3 comments
Closed

Empty relationships should have data key with value null #38

JakeDluhy opened this issue Dec 7, 2017 · 3 comments

Comments

@JakeDluhy
Copy link

JakeDluhy commented Dec 7, 2017

Per spec: http://jsonapi.org/format/#document-resource-object-relationships A “relationship object” MUST contain at least one of the following: links, data, meta. Implementations I've seen in the past will have "posts": { "data": null } } within the relationships object if the relation doesn't exist/isn't provided.

However with schema like

module.exports = {
  whitelist:     ['name'],
  relationships: {
    players: { type: 'players' },
    turns:   { type: 'turns' },
    map:     { type: 'maps' },
  },
};

my json comes out like

{
    "jsonapi": {
        "version": "1.0"
    },
    "data": {
        "type": "campaigns",
        "id": "10",
        "attributes": {
            "name": "My New Campaign"
        },
        "relationships": {
            "players": {},
            "turns": {},
            "map": {}
        }
    }
}

I'm saying it should be like

"relationships": {
    "players": { "data": null },
    "turns": { "data": null },
    "map": { "data": null }
}

I looked through the source to see if I could make a PR but I couldn't find where this is happening... It seems like at the very least from https://github.com/danivek/json-api-serializer/blob/master/lib/JSONAPISerializer.js#L582 it should have data: undefined

@danivek
Copy link
Owner

danivek commented Dec 7, 2017

You're right.
It's related to this commit: 12bc2cd

Return null instead of undefined will do the job i think.

@JakeDluhy
Copy link
Author

Want me to make a PR for it?

@danivek danivek closed this as completed in 060fc40 Dec 8, 2017
@danivek
Copy link
Owner

danivek commented Dec 8, 2017

fix in v1.10.1

Thanks

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

2 participants