-
-
Notifications
You must be signed in to change notification settings - Fork 765
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
jsonschema validation #936
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR relies on internet connection. Please change that.
Many of the tests seem to fail because the OpenAPI specs used for testing are actually invalid. |
Hey @patrickkwang - I'm excited for these changes - thanks for taking them on! |
Could you make the tests pass? |
No, the tests will fail because many of them are based on the invalid The tests are corrected in #1010, so this PR will be dependent on that one. |
It looks like the jsonschema version doesn't check the case where a parameter default is the wrong type, and this results in two failing tests. |
The JSON Schema actually doesn't enforce that default values validate against the associated schema: |
Here's the relevant section from the spec.
This PR uses jsonschema to validate the openapi spec. I think this is a bug in their openapi spec validation as implemented with jsonschema. (the language here is very confusing - ack!) |
Also of note, this doesn't completely alleviate the need for |
07b682b
to
39fc35c
Compare
It turns out it's not too hard to extend jsonschema to enforce that all the default values validate against the associated (sub)schemas. The last two tests pass now! This |
nice! I tried to ask in the swagger irc if there's a way to do it in jsonschema, but didn't hear back. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @patrickkwang, I hope you're still interested in getting this merged!
The changes look good, I left one comment.
We also switched to the main
branch, so would be great if you can retarget and rebase / merge.
connexion/spec.py
Outdated
@@ -207,17 +244,21 @@ def base_path(self, base_path): | |||
|
|||
@classmethod | |||
def _validate_spec(cls, spec): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is now the same in both classes, so we should be able to lift this to the base Specification
class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
schema_string = pkg_resources.resource_string('connexion', 'resources/schemas/v2.0/schema.json') | ||
openapi_schema = json.loads(schema_string.decode('utf-8')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about del schema_string
after loading openapi_schema
, we waste quite some memory here...
Addresses #930.
Changes proposed in this pull request: