Exchema
This is still a WIP. More details later =D
Installation
Add exchema to your list of dependencies in mix.exs:
def deps do
[
{:exchema, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exchema.
Internals
Exchema works with some important pieces:
Transformer It is the common definition between a coercion and a validation.
It is a function that receives a value, a list of arguments and returns either an
{:error, description}or an:okor{:ok, new_value}I.E., a validation returns either an error or an ok whilist a coercion returns either a new value or an error.
TransformerFinder This implements a function that receives a transformation definition and returns either nil or a transformer.
Work to do
- Define schema internal representation
- Create parser that parses and transforms a given input
- Create DSL to
- Allow DSL to generate struct
- Add schema-level transformations
- Implement type coercion for
- Integer
- Float
- Date (ISO 8601)
- Time (ISO 8601)
- NaiveDateTime (ISO 8601)
- DateTime (ISO 8601)
- Other Schemas
- Implement transformaitons for the following libs (and extract later)
- UUID
- Vex (validation)
Maybe the generation of struct can be defined as a after-schema def plugin that would enable other extensions such as generating a Ecto.Schema (bonus for generating changeset validations automagically) in external libraries.