A bit different approach to external validators plus validation against definition in a schema #53
A bit different approach to external validators plus validation against definition in a schema #53arentrue wants to merge 25 commits intofor-GET:masterfrom
Conversation
| throw:Error -> {error, Error} | ||
| end. | ||
|
|
||
| %% @doc Equivalent to {@link validate_definition/4} where `Options' is an empty list. |
src/jesse_schema_validator.erl
Outdated
| NewState = validate_with_state(JsonSchema, Value, State), | ||
| {result(NewState), Value}. | ||
|
|
||
| %% @doc Validates json `Data' against `Definition' in `JsonSchema' with `Options'. |
There was a problem hiding this comment.
According to Elvis:
Line 65 is too long: %% @doc Validates json
Data' againstDefinition' inJsonSchema' withOptions'..
| init_validator_state(undefined, _) -> | ||
| undefined; | ||
| init_validator_state(Validator, Opts) -> | ||
| Validator:init_state(Opts). |
There was a problem hiding this comment.
According to Elvis:
Remove the dynamic function call on line 287. Only modules that define callbacks should make dynamic calls.
|
thanks for finally opening a PR ! :) it will take a while to look through it, but I've always wanted to do this but time never knocked on its door. as for the functionality to validate against a schema under If you have the time, I suggest this:
ping @lazedo : feedback is most welcome! |
|
@andreineculau sure, I'll split the PR into two and follow the rest of the proposed points. A note regarding the
Since in the application where I use jesse, it is possible to reliably keep the schema (essentially a jesse state) by the application, I've changed jesse API from Suggestions for a better approach to implementing that API for validation against a subschema available at particular JSON pointer, are very welcome! |
|
@arentrue i think the initial external validators may not be fully explained. we have draft3/draft4 schemas that validate data, and.., for business extensions (validate a customer in a database, ....) we use the extension validator by using the callback. we look for annotated schema elements and perform whatever we want as an extra validation. |
Co-authored-by: Sergey Yelin <elinsn@gmail.com>
avoid deprecated http_uri functions
Hi, I'd propose a bit different approach to external validators: allow pluggable validator modules which follow validator interface, the same as used for draft3 and draft4 validators, and can be built on top of those default validators as well as override any rule or implement totally independent validation logic. I think, that is rather more flexible approach, than just allowing some post validation after all the default rules have been successfully validated. It will also allow to update
jesse_validator_draft4code, removing unnecessary code duplication withjesse_validator_draft3.This PR also introduces
jesse:validate_definition/3/4interface to validate a value against a particular definition in thedefinitionssection of a schema.I see, that you've just merged alternative implementation for external validators (I should have created this PR some weeks ago!), thou I hope you'll consider this PR. If you find this PR interesting and I'll prepare it for the merge (rebase, etc).