Skip to content

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.

@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