Skip to content

Expose deserialization reverse mapping in controllers #27

@beauby

Description

@beauby

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

  • An ActionController instance method, possibly named jsonapi_pointers
  • Other suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions