JSV.StructSupport (jsv v0.4.0)

View Source

Utilities to work with structs defined by schemas.

Summary

Functions

Returns a keyword list of default values for the given schema. The list is sorted by keys.

Returns a list of {binary_key, atom_key} tuples for the given schema. The list is sorted by keys.

Returns the required property of the schema or an empty list.

Validates the given raw schema can be used to define a module struct or raises an exception.

Functions

data_pairs(schema)

@spec data_pairs(JSV.raw_schema()) :: keyword()

Returns a keyword list of default values for the given schema. The list is sorted by keys.

The schema must be valid against validate!1/.

keycast_pairs(schema)

@spec keycast_pairs(JSV.raw_schema()) :: [{binary(), atom()}]

Returns a list of {binary_key, atom_key} tuples for the given schema. The list is sorted by keys.

The schema must be valid against validate!1/.

list_required(schema)

@spec list_required(JSV.raw_schema()) :: [atom()]

Returns the required property of the schema or an empty list.

The schema must be valid against validate!1/.

validate!(schema)

@spec validate!(JSV.raw_schema()) :: :ok

Validates the given raw schema can be used to define a module struct or raises an exception.

It will check the following:

  • Schema defines a type object.
  • Schema has properties.
  • properties is a map with atom keys.
  • required, if present, contains only atoms