View Source Parameter.Field (Parameter v0.6.0)
The field inside a Parameter Schema have the following structure:
field :name, :type, opts
:name
- Atom key that defines the field name:type
- Type fromParameter.Types
. For custom types check theParameter.Parametrizable
behaviour.:opts
- Keyword with field options.
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 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.
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