View Source JSONAPIPlug.Document (jsonapi_plug v1.0.5)

JSON:API Document

This module defines the structure of a JSON:API document and functions that handle serialization and deserialization. This also handles validation of JSON:API documents.

https://jsonapi.org/format/#document-structure

Summary

Types

JSON:API Primary Data

JSON:API Errors

JSON:API Included Resources

JSON:API Object

JSON:API Links

JSON:API Meta Information

t()

JSON:API Document

Functions

Deserialize JSON:API Document

Serialize a Document struct representing a JSON:API Document

Types

JSON:API Primary Data

https://jsonapi.org/format/#document-top-level

@type errors() :: [JSONAPIPlug.Document.ErrorObject.t()]

JSON:API Errors

https://jsonapi.org/format/#errors

@type included() :: [JSONAPIPlug.Document.ResourceObject.t()]

JSON:API Included Resources

https://jsonapi.org/format/#document-compound-documents

JSON:API Object

https://jsonapi.org/format/#document-jsonapi-object

@type links() :: %{required(atom()) => JSONAPIPlug.Document.LinkObject.t()}

JSON:API Links

https://jsonapi.org/format/#document-links

@type meta() :: payload()

JSON:API Meta Information

https://jsonapi.org/format/#document-meta

@type payload() :: %{required(String.t()) => value()}
@type t() :: %JSONAPIPlug.Document{
  data: data() | JSONAPIPlug.Resource.data() | nil,
  errors: errors() | nil,
  included: included() | nil,
  jsonapi: jsonapi() | nil,
  links: links() | nil,
  meta: meta() | nil
}

JSON:API Document

https://jsonapi.org/format/#document-structure

@type value() ::
  String.t()
  | integer()
  | float()
  | [value()]
  | %{required(String.t()) => value()}
  | nil

Functions

@spec deserialize(payload()) :: t() | no_return()

Deserialize JSON:API Document

Takes a map representing a JSON:API Document as input, validates it and parses it into a t/0 struct.

@spec serialize(t()) :: t() | no_return()

Serialize a Document struct representing a JSON:API Document

Takes a t/0 struct representing a JSON:API Document as input, validates it and returns the struct if valid.