View Source Parameter.Field (Parameter v0.6.0)

The field inside a Parameter Schema have the following structure:

field :name, :type, opts

options

Options

  • :key - This is the key from the params that will be converted to the field schema. As an example, when of the param comes with a camelCase for mapping first_name, this option should be set as "firstName". If this parameter is not set it will default to the field name.
  • :default - default value of the field when no value is given to the field.
  • :required - defines if the field needs to be present when parsing the input.
  • :validator - Validation function that will validate the field after loading.
  • :virtual - if true the field will be ignored on Parameter.load/2 and Parameter.dump/2 functions.

example

Example

As an example having an email field that is required and needs email validation could be implemented this way:

field :email, :string, required: true, validator: &Parameter.Validators.email/1

Link to this section Summary

Link to this section Types

@type t() :: %Parameter.Field{
  default: any(),
  key: binary(),
  name: atom(),
  required: boolean(),
  type: Parameter.Types.t(),
  validator: (... -> any()),
  virtual: boolean()
}