Closed sjaensch closed 4 years ago
I'll be checking this later this evening. Attaching the scope seems a good idea, but I'm curious on how we didn't noticed this before. Is that possible that we were essentially never validating this?
By the way I would check if you can reproduce the issue by using #/definitions/...
instead of #definitions/...
(if my memory is not wrong that can be triggering the issue)
Yes, due to #134 we were never validating array item schemas. I'll check later or tomorrow morning whether our specs use #/definitions/
or #definitions/
, but I single-stepped through this issue and could observe that within the call to deref
it only had the root swagger spec, and tried to find it within the definition
section there. That's why we do the whole x-scope
annotation work for jsonschema.
We're still encountering validation errors internally due to the fact that since version 2.7.0 array item definitions are properly validated (see #134).
Example traceback:
The reason why the ref is unresolvable is that it has no scope attached - we do this manually in
deref_and_validate
. This is important in the case of specs split across multiple files. The reason it has no scope is that we exit too early when we detect a cycle, not attaching the scope first. This is fine if the schema in question can be reached in other ways, but there's cases like the one I added to the test, where theanswer
property of thequestion
definition will only ever be reached once, while following the response spec →answer
→question
. If we don't attach a scope to theanswer
property jsonschema won't be able to deref it, as without the attached scope it will only have the root schema document, which does not contain the definition foranswer
.This is not a problem for the rest of the spec in
tests/data/v2.0/test_complicated_refs
, as it puts paths and definitions into well-known root elements of the swagger spec, which we don't always do internally.The test case I added causes
tests/validator20/validate_spec_test.py::test_complicated_refs
to fail on master, while it passes on my branch.