jesse
jesse copied to clipboard
Add support for configurable and extendable validators
This is one of the two PRs which are the result of PR https://github.com/for-GET/jesse/pull/53 split.
@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. we still want to use v3/v4 validators for types, ranges, whatever. we are only interested in providing an extra layer of validation not tied to jesse core library not replacing by a custom validator.
@lazedo thanks for the explanation. Yes, that is also clear from the code and description in your initial PR.
The reason I still propose this PR is because it provides a superset of the functionality you've implementated. In addition to the extra validation of annotated schema elements on top of draft4/draft3 it allows easily override original validation logic of a base validator (e.g. draft3 or draft4) for particular schema element. It also allows to create a new custom validator modules altogether.
In my opinion, it also corrects the initial validation API in jesse, moving the looping over schema into the common jesse_schema_validator module and leaving validator modules only pure validation functionality with a clean interface for that.
@arentrue thanks for the reply, but how would you validate a draft4+(custom for a single field)?
Note that we're now working on standardizing how schemas can be extended. https://github.com/json-schema-org/json-schema-spec/issues/602 is an example. It's working through some particularly complex cases involving newly proposed keywords, and it's a lot of ideas that are new and somewhat tentative. But anyone who is interested in making extensible implementations may want to look at that issue and https://github.com/json-schema-org/json-schema-spec/issues/561