-
-
Notifications
You must be signed in to change notification settings - Fork 595
Description
I'm working with a custom metaschema that is a superset of draft 4, is there/will there be a way to select the draft 4 dialect when creating a Validator class? Currently the create method is choosing the opaque dialect when it fails to recognize our metaschema's id:
https://github.com/python-jsonschema/jsonschema/blob/v4.18.0a1/jsonschema/validators.py#L187
and the referencing package doesn't appear to offer a sanctioned method for registering a new dialect id:
https://github.com/python-jsonschema/referencing/blob/v0.24.4/referencing/jsonschema.py#L544-L556
Is there another way to accomplish this that I'm missing? And if not, are you open to adding something like a default_specification
argument to the create method?
By the way, thanks a lot for providing an alpha release, it's super helpful to be able to work through our issues ahead of time.
Activity
Julian commentedon Mar 19, 2023
This will happen before the real release, probably this week! Thanks for indicating someone is paying attention :D
Expect an update in the next few days but it'll look basically like what you expect I hope!
Julian commentedon Mar 19, 2023
(to be even more specific no changes should be required on your part though you certainly can choose to make some to get improved behavior, and also there will be a be another beta!)
eslavich commentedon Mar 19, 2023
Huzzah! I'll keep an eye out for it.
$ref
&$dynamicRef
support /RefResolver
with the new referencing library #1049unevaluatedProperties: false
is applied to the parent object #1087id_of
argument tovalidators.create
and theID_OF
attribute onValidator
s #1091Julian commentedon Apr 25, 2023
I want to clarify something that I didn't notice until now --
@eslavich are you specifically calling
jsonschema.validators.create
and notextend
? I assumed (or misread) that you meant the latter (and were surprised that extending a validator didn't preserve its resolving behavior, which is why I labelled this a bug).Are you instead talking about a totally unrelated validator/dialect you created with
.create
which you happened to define a keyword called$ref
for?braingram commentedon Jul 6, 2023
I've been testing asdf with the new 4.18 and I think I might have a minimal example that illustrates why we need to define a specification (and the opaque specification results in resolution errors).
For asdf we define a meta-schema based off draft4 (the details probably aren't important but I'm happy to supply as much as you'd like). Since this metaschema is not registered with referencing.jsonschema._SPECIFICATIONS creating a validator with the metaschema results in an opaque specification and failures due to inability to resolve references.
Here's a minimal example that was compatible with 4.17:
When run with 4.17.3 this executes with no error. When run with 4.18.0 this shows the expected
DeprecationWarning
forRefResolver
and errors out as follows:If I modify the example to use referencing (am I doing this right?):
The example fails with the following traceback:
Julian commentedon Jul 6, 2023
Thanks, that's definitely helpful, I'll have a look more carefully in the morning, but just to be sure, why are you calling
create
and notextend
there if you're simply trying to add some stuff to draft4?braingram commentedon Jul 6, 2023
Thanks for the quick response and for the good question. I have not tried swapping 'create' for 'extend'. A simple swap (and removing the id_of and meta_schema arguments) in asdf does not appear to work but I'm not quite sure why yet.
Is there a way to define a meta schema with extend?
Julian commentedon Jul 7, 2023
When I first added the API I mistakenly didn't add one, assuming that generally one wasn't going to change the metaschema -- if this is what's preventing you from using it I'm happy to add an argument for it, though otherwise I wasn't planning on it because eventually the entire API may need deprecating unfortunately due to the new "Vocabulary System" in newer drafts of JSON Schema (which mean that now there's some concept of groups of validators). But yeah if it's useful I can add it if it turns out there's some other reason your quick experiment didn't work.
Initially what you shared looks like a bug (at least inasmuch as the behavior should not change for
RefResolver
certainly) but will need to do some more diagnosis. Thanks again for the feedback, I definitely do want to make this work in a way that requires no hacks for you guys and is indisputably better than before.7 remaining items