Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external format validators option #85

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

abogosyan
Copy link

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" },
}

Copy link
Contributor

@seriyps seriyps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I Added some notes. No "critical" issues, just something to discuss.

src/jesse_validator_draft3.erl Show resolved Hide resolved
src/jesse_validator_draft3.erl Show resolved Hide resolved
src/jesse_validator_draft4.erl Show resolved Hide resolved
@seriyps
Copy link
Contributor

seriyps commented Nov 4, 2019

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

@abogosyan
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants