optimal v0.3.6 Optimal.Schema View Source

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

Link to this section Summary

Functions

Merges two optimal schemas to create a superset schema

Create a new schema

Link to this section Types

Link to this type t() View Source
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()
}

Link to this section Functions

Link to this function merge(left, right, opts \\ []) View Source
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.”

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.