jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
321 stars 63 forks source link

Expose deserialization reverse mapping in controllers #27

Closed beauby closed 7 years ago

beauby commented 7 years ago

When a payload is deserialized, a set of json pointers for the deserialized fields is generated, which can then be used when serializing errors.

Example

# Incoming payload
{
  data: {
    id: "1",
    type: "users",
    attributes: {
      name: "Lucas",
      email: "lucas@jsonapi-rb.org"
    },
    relationships: {
      posts: {
        data: [{ type: "posts", id: "2" }, { type: "posts", id: "3" }]
      }
    }
  }
}

# Deserialized params (via `deserializable_resource :user`)
{
  id: "1",
  type: "users",
  name: "Lucas",
  email: "lucas@jsonapi-rb.org",
  post_ids: ["2", "3"],
  post_types: ["posts", "posts"]
}

# Reverse mapping / json pointers
{
  id: "/data/id",
  type: "/data/type",
  name: "/data/attributes/name",
  email: "/data/attributes/email",
  post_ids: "/data/relationships/posts/data",
  post_types: "/data/relationships/posts/data"
}

Possible interface

beauby commented 7 years ago

Closed by #29.