View Source Parameter.Field (Parameter v0.5.4)

This module define the structure of a Field inside a Parameter Schema. The field follow the structure:

field :field_name, :field_type, opts

The :field_type are types implemented on Parameter.Types or custom modules that implements the Parameter.Parametrizable behaviour.

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