jesse icon indicating copy to clipboard operation
jesse copied to clipboard

Add external format validators option

Open abogosyan opened this issue 5 years ago • 3 comments

The idea is similar to external_validator option

This option allows you to define own string formats and validate it with any fun(binary()) -> ok | error. For example:

Validators = #{
   %% validates "IPV4:PORT" string, like "127.0.0.1:5050
   <<"ipv4_and_port">> => fun ipv4_and_port_validator/1
}, 
JesseOptions = [{external_format_validators, Validators}],
jesse:validate_with_schema(SchemaJson, ConfigJson, JesseOptions)

And somewhere in schema:

properties": {
    "str_key":   { "type": "string", "format": "ipv4_and_port" },
}

abogosyan avatar Oct 31 '19 09:10 abogosyan

Oh, sorry, I completely forgot about two other things:

  • would you mind adding a few tests for this feature?
  • it would be also cool to mention it in a README

seriyps avatar Nov 04 '19 12:11 seriyps

Oh, sorry, I completely forgot about two other things:

  • would you mind adding a few tests for this feature?
  • it would be also cool to mention it in a README

Will do, when i have free time :(

abogosyan avatar Nov 11 '19 07:11 abogosyan

Finally, I've added few tests and little readme, also fixed linter errors and made compatible for erlang versions without maps support, please check.

abogosyan avatar Apr 17 '20 12:04 abogosyan