zoedsoupe / peri

Elixir library for declarative data description and validation
MIT License
84 stars 2 forks source link

[FEATURE] Type refinements as Keyword #11

Open dvv opened 3 months ago

dvv commented 3 months ago

Description Right now we can not AFAICS apply several constraints to a type, e.g.:

{:string, {:min, 1}, {:max, 2}}

Would IMO be nice to handle such cases in form of Keyword options:

{:string, min: 1, max: 2}

Motivation To handle richer validation technique.

Alternatives None AFAICS

zoedsoupe commented 3 months ago

interesting! the example you gave could be easily solved with a new directive for the :string type like it exists for the :integer one. something like {:range, min, max},

do you have any other examples that could be benefit with these keyword (aka multiple) validation directives?

dvv commented 3 months ago

Nope, nothing ATM

zoedsoupe commented 2 months ago

i was thinking and there're some constraints that doesn't make semantical sense to be together, and those will cause unexpected results, like:

{:integer, gt: 3, lt: 2}

so probably we want to filter and parse what are valid constraints, and i don't think this should be tackled right now.

do you think in any other simpler solution for this problem?