Git Product home page Git Product logo

Comments (4)

aren55555 avatar aren55555 commented on May 4, 2024

As a client this is definitely a valid scenario. You construct the entity client side, and when the server saves the entity it assigns and returns the id.

This library was originally abstracted out of a project where our original use case was a go jsonapi server. As such, we only considered the server use case for the id field.

With that being said it should not be that hard to add the omitempty feature to the id annotation. If you want to take a stab at it, I'd be happy to review your pull request. Otherwise it may be a few weeks before I can spend time on this.

from jsonapi.

mitchellh avatar mitchellh commented on May 4, 2024

For me its as simple as adding omitempty to the ID field of Node, but I'm not sure of the ramifications of this. Do you think this would negatively affect any usage? I haven't read the spec carefully enough to be 100% certain...

If you think that's all it takes I'd be happy to make that PR.

from jsonapi.

aren55555 avatar aren55555 commented on May 4, 2024

Initially I thought we would allow the developer to annotate their structs' id field with omitempty. However (as far as I'm aware) I don't see why you would ever want to transmit an empty string id. The example below is JSONAPI spec complaint (as the ID is a string), but not sensible to transmit:

{
    "data": {
        "type": "foo",
        "id": "",
        "attributes": {...}
    }
}

Which means it is seemingly OK to annotate Node's ID field with a vanilla json omitempty.

Thoughts @shwoodard ?

from jsonapi.

mitchellh avatar mitchellh commented on May 4, 2024

Right, and the other issue is even if we could just annotate jsonapi:"primary,type,omitempty", because Node doesn't have omitempty on ID, it would still transmit a blank ID. So eventually we'd have to get there anyways. :)

from jsonapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.