Restrict --validator-class to types (no functions)
Add tests for custom validator usage
Add doc section covering --validator-class
The basics are all here, and this should resolve #262
For users seeing this, and for comparison with the old jsonschema CLI
feature, 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 in
the 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 validators
check-jsonschema has a few features which expect the validator class to
be built only using the documented jsonschema interfaces. In particular:
--fill-defaults uses the extend API to modify the validator class
a referencing registry is used (rather than RefResolver) and is passed
on init
a custom format checker is passed on init, and it is not derived from
FORMAT_CHECKER on the --validator-class value
Usages may change over time as jsonschema and check-jsonschema continue
to 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 the
jsonschema API contract and it causes issues with a custom validator, that
is 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 some
measure of change to make it easier to control dependency versions used, but
check-jsonschema also has pre-commit hook usage to consider, with its own
implications about appropriate dependency specification
check-jsonschema currently will not call check_schema when using a custom
validator 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 it
typically has to be a proper python class. The possibility of some callback
or 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".
--validator-class
The basics are all here, and this should resolve #262
For users seeing this, and for comparison with the old
jsonschema
CLI feature, 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
in the old CLI -- you must separate your module name from your class name with a colon, as infoopkg.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 to be built only using the documentedjsonschema
interfaces. In particular:--fill-defaults
uses theextend
API to modify the validator classreferencing
registry is used (rather thanRefResolver
) and is passed on initFORMAT_CHECKER
on the--validator-class
valueUsages may change over time as
jsonschema
andcheck-jsonschema
continue to evolve. Barring major issues, I do not intend to treat incompatibility between a custom validator class andcheck-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, that is 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 some measure of change to make it easier to control dependency versions used, butcheck-jsonschema
also has pre-commit hook usage to consider, with its own implications about appropriate dependency specificationcheck-jsonschema
currently will not callcheck_schema
when using a custom validator 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 it typically has to be a proper pythonclass
. The possibility of some callback or 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".