How do validate against a single file containing multiple schemas? #1045
Unanswered
mdavis-xyz
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Oh I think I found the answer. Using This was not obvious. Perhaps we can add an FAQ, or some general documentation about this?
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an OpenAPI spec. Here's a minimal example:
I have a python dictionary, like:
How can I validate that this dictionary is an instance of
components.schemas.Item
?Attempts
Attempt 1
Expected behavior: Script passes
Actual behavior:
So it's stuck on resolving the reference. Fair enough, since the
schema
I passed was only thedefinitions/Item
subset, which does not containdefinitions/MyThing
.Attempt 2
expected behavior: script runs without throwing exception
actual behavior: script runs without throwing exception
But hang on, how did
jsonschema
know which of the two schemas in the file to validate against?Let's check that it can detect an invalid schema.
Attempt 3
expected behavior: Script runs without throwing an exception.
Actual behavior:
So it's not detecting invalid schemas. It's just saying everything is valid.
Next steps
So now I'm stuck. This is probably related to resolvers. The documentation for
validate()
does not mention aresolver
argument, even though examples elsewhere in the docs use it. How am I supposed to know thatresolvers is a valid
kwargfor
validate()`?Anyway, let's try to pass a
RefResolver
via the hiddenresolver
kwarg
.As mentioned in discussion 1044, I don't know what the second argument to
RefResolver
should be. I'm also not sure whatbase_uri
should be, since I loaded the spec from disk into a dictionary myself. I'm not expecting the library to read anything from disk.Attempt 4
Same result:
Hmm, that top half of the error is interesting:
This suggests to me that the FAQ is possibly wrong, and
referrer
should not be a bool?Attempt 5
Change
to
Same traceback, except instead of being about bools, it says:
Conclusion
I'm lost. I can't figure out how to use this library to validate a dictionary matches a definition inside a single OpenAPI yaml file, with internal references.
Can someone please explain to me how to do this?
Beta Was this translation helpful? Give feedback.
All reactions