-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Resolving a $ref
to a nested definition can fail to catch that a (bad) subschema is neither bool nor object, resulting in an AttributeError
#119
Comments
Thanks (as usual) for the detailed report and thoughts. This isn't the first time I've thought about this sort of thing -- my first reaction which I still want to at least attempt pursuing is that this kind of thing is probably something that needs improving at the I'm going to leave this open regardless and have another think/look at it -- just sharing the first reactions. |
This makes sense to me. It's just at a weird boundary where the contracts between components are not as clean as I would like -- I'd really like it if we could verify that a schema won't "break The contract with But it makes it hard to decide how to handle this in an application which takes a schema as input. Sticking with Perhaps another way of looking at this is that Should |
Yes (which maybe is a funny contract, but happens to be the same one as
|
.. no idea what just sent that comment, I was mid-typing and hit nothing else -- anyways ...
I think until
I think maybe this is related to #68 -- i.e. having a registry where when you put resources in it, calls out to a library to ensure those resources are valid. That's the sort of thing such a callable woud do right? Like I say in that issue, I think we'd still want to stay "agnostic" to validator libraries, but then yes I think having one in |
This originates downstream in python-jsonschema/check-jsonschema#376 . I was just able to look at the offending schema and trace things out enough to find the true cause. I've stuck with using the CLI for my reproducers, but I could work up some python for this if it would be useful.
check-jsonschema
is usingjsonschema
+referencing
. It keeps thejsonschema
behavior of checking a schema against its metaschema. Therefore, the following schema is caught as invalid:invalid-caught-by-metaschema
(Note how the definition for
"foo"
is a string, rather than a schema.)However, if the invalid definition is nested, as follows, the metaschema check is not sufficient:
invalid-not-caught-by-metaschema
As a result, it is possible, with
jsonschema
+referencing
, to be handling this in a validator. The next step is to try to use it.With the
check-jsonschema
CLI, we get the following trace (trimmed to relevant parts):full-cli-traceback
This shows an error in
jsonschema
(not quite atreferencing
yet!). I had to tinker around with things to find the right trigger conditions, but this seems to do the trick, as a nasty schema:Now, trying to use it triggers an attempt to call
.get()
on a string:Proposed Resolution
Obviously, the best resolution is for such a schema to never get written, since it's invalid. 😁
And I'll be trying to advise the upstream provider of the schema against nesting things under
definitions
, since it weakens the kind of checking which is possible.But should various
referencing
internals be more wary that an input may be a dict, a bool, or something unwanted/unexpected? Or shouldreferencing
check for bad inputs more aggressively when loading data?The goal here is to have a better and clearer error in this case, not to ignore the malformed schema.
I think the best thing here is that one of the levels of document loading in
Referencing
checks if the value isdict | boolean
. If we only consider JSON Schema, it could be a validator onResource.contents
. That makes the most sense to me, conceptually, for JSON Schema, but it ties in non-generic details of that spec (vs more general$ref
resolution). PerhapsJSONSchemaResource(Resource)
is the right thing, which adds said validation?(NB: I'm reading a lot of the internals pretty quickly and for the first time, so my ideas here may not hold up.)
The text was updated successfully, but these errors were encountered: