Optimal.Schema (optimal v0.3.7)

View Source

Functions for generating and validating the opts that generate a schema.

Summary

Functions

Merges two optimal schemas to create a superset schema.

Create a new schema.

Types

t()

@type t() :: %Optimal.Schema{
  annotations: Keyword.t(),
  custom: Keyword.t(),
  defaults: Keyword.t(),
  describe: Keyword.t(),
  extra_keys?: boolean(),
  opts: [atom()],
  required: [atom()],
  types: Keyword.t()
}

Functions

merge(left, right, opts \\ [])

@spec merge(left :: t(), right :: t(), opts :: Keyword.t()) :: t()

Merges two optimal schemas to create a superset schema.


Opts

  • annotate(:string): Annotates the source of the opt, to be used in displaying documentation.
  • add_required?(:boolean): "If true, all required fields from left/right are marked as required. Otherwise, only takes required fields from the left."

new()

@spec new() :: t()

Create a new schema.


Opts

  • opts([{:list, :atom}, :keyword]): A list of opts accepted, or a keyword of opt name to opt type - Default: []
  • required({:list, :atom}): A list of required opts (all of which must be in opts as well) - Default: []
  • defaults(:keyword): A keyword list of option name to a default value. Values must pass type rules - Default: []
  • extra_keys?(:boolean): If enabled, extra keys not specified by the schema do not fail validation - Default: false
  • custom(:keyword): A keyword list of option name (for errors) and custom validations. See README - Default: []
  • describe(:keyword): A keyword list of option names to short descriptions (like these) - Default: []

A custom validation is run on the types provided at schema creation time, to ensure they are all valid types.

new(opts)

@spec new(opts :: Keyword.t()) :: t() | no_return()