Add --validator-class option for passing a validator class #327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
--validator-class
The basics are all here, and this should resolve #262
For users seeing this, and for comparison with the old
jsonschema
CLIfeature, I have a few notes on the interface and some related topics:
--validator-class
is the option name (there is no short opt)The syntax for specifying this is slightly different from
--validator
inthe old CLI -- you must separate your module name from your class name with
a colon, as in
foopkg.barmodule:MyValidator
.This could be loosened to the purely dotted notation if there's a strong
argument for doing so, but the interface is simpler and cleaner with this
syntax, so please think critically about whether or not it's important
before asking for it to change.
As an example usage,
--validator-class 'jsonschema.validators.Draft3Validator'
.There is no special case for the
jsonschema
builtin validatorscheck-jsonschema
has a few features which expect the validator class tobe built only using the documented
jsonschema
interfaces. In particular:--fill-defaults
uses theextend
API to modify the validator classreferencing
registry is used (rather thanRefResolver
) and is passedon init
FORMAT_CHECKER
on the--validator-class
valueUsages may change over time as
jsonschema
andcheck-jsonschema
continueto evolve. Barring major issues, I do not intend to treat incompatibility
between a custom validator class and
check-jsonschema
behaviors as a bug.The above stated, if
check-jsonschema
is doing something outside of thejsonschema
API contract and it causes issues with a custom validator, thatis a bug; please report any of those and we can get them fixed. :)
Within the scope of this change, no change is being made to the dependency
bounds being applied by
check-jsonschema
. There will probably be somemeasure of change to make it easier to control dependency versions used, but
check-jsonschema
also has pre-commit hook usage to consider, with its ownimplications about appropriate dependency specification
check-jsonschema
currently will not callcheck_schema
when using a customvalidator class (please open an issue if you would like this to change; it is
a point of flexibility based on user demand)
The CLI validation currently requires that the value be a
type
, meaning ittypically has to be a proper python
class
. The possibility of some callbackor alternative extension point is open if a well-reasoned proposal for some
secondary behavior can be made.
All of the decisions being made here about the interface, implicit API
contract, and expectations are subject to change if there's a good reason.
After all, this is an advanced feature for "power users".