-
Notifications
You must be signed in to change notification settings - Fork 63
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
A bit different approach to external validators plus validation against definition in a schema #53
base: master
Are you sure you want to change the base?
Conversation
@@ -150,6 +152,44 @@ validate(Schema, Data, Options) -> | |||
throw:Error -> {error, Error} | |||
end. | |||
|
|||
%% @doc Equivalent to {@link validate_definition/4} where `Options' is an empty list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/jesse_schema_validator.erl
Outdated
@@ -45,6 +62,21 @@ validate(JsonSchema, Value, Options) -> | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to Elvis:
Line 65 is too long: %% @doc Validates json
Data' against
Definition' inJsonSchema' with
Options'..
init_validator_state(undefined, _) -> | ||
undefined; | ||
init_validator_state(Validator, Opts) -> | ||
Validator:init_state(Opts). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
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_draft4
code, removing unnecessary code duplication withjesse_validator_draft3
.This PR also introduces
jesse:validate_definition/3/4
interface to validate a value against a particular definition in thedefinitions
section 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).