jesse
jesse copied to clipboard
Add external format validators option
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" },
}
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
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 :(
Finally, I've added few tests and little readme, also fixed linter errors and made compatible for erlang versions without maps support, please check.