View Source Resourceful.JSONAPI.Fields (Resourceful v0.1.4)

Functions for validating fields, primarily for use with JSON:API sparse fieldsets. Fields are provided by type type_name in requests and not inferred from root or relationship names. This means that if a type has multiple relationships pointing to a single type or a self-referential relationships, these will be applied to all instances of that type type_name regardless of its location in the graph.

Since this is specific to JSON:API, field names are not converted to atoms in the generation options after successful validation. There's no need since these prevent any mapping from occurring and never make it to the data layer.

It's also important to note that a "field" is specifically defined and is a collection of attribute names and relationship names. It specifically excludes id and type despite all identifiers sharing a common namespace.

NOTE: Relationships are currently not supported.

Link to this section Summary

Functions

Takes a map of fields by type type_name (e.g. %{"albums" => ["releaseDate", "title"]}) and validates said fields against the provided type. If fields are included that are not part of a particular type, errors will be returned.

Link to this section Functions

Link to this function

validate(type, fields_by_type)

View Source

Takes a map of fields by type type_name (e.g. %{"albums" => ["releaseDate", "title"]}) and validates said fields against the provided type. If fields are included that are not part of a particular type, errors will be returned.