Code Monkey home page Code Monkey logo

Comments (1)

ethanresnick avatar ethanresnick commented on July 23, 2024

So, there are two distinct things going on here.

The first is that the json-api library is trying to read your schema to automatically generate documentation, and, as you suggest, it's having trouble with arrays of embedded objects. That's definitely a bug/missing feature, and I'll keep this issue open as a reminder to add it.

But there's a deeper problem here, which is that the JSON API specification, which this library merely implements, doesn't (yet) support nesting data in the way you're trying to do. Here's the relevant paragraph from the spec:

Complex data structures involving JSON objects and arrays are allowed as attribute values. However, any object that constitutes or is contained in an attribute MUST NOT contain a relationships or links member, as those members are reserved by this specification for future use.

In other words, having a messages attribute that holds an array of objects is ok, but those objects can't have a relationship to other model(s), so the author relationship to User is impossible.

There has been much discussion about allowing relationships in object attributes, and it may well happen—but not for at least a few months. These spec things move slowly, unfortunately.

For now, therefore, I'd suggest making message into it's own model, and having message contain a relationship to the discussion that owns it (or vice-versa). Then everything will work smoothly with this library and the specification.

from json-api.

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.