View Source Parameter.Field (Parameter v0.5.3)
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.
The other options available for the field are:
key
: This is the key on the external source that will be converted to the param definition. As an example, when receiving data from an external source that uses a camelCase for mappingfirst_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
: iftrue
the field will be ignored onParameter.load/2
andParameter.dump/2
functions.
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