-
Notifications
You must be signed in to change notification settings - Fork 45
Delegate spec validation to swagger_spec_validator.
#86
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
Conversation
|
Changes Unknown when pulling 8b90e1a on prat0318:introduce_ssv into * on striglia:master*. |
tests/api_test.py
Outdated
| @@ -24,25 +22,24 @@ def test_basepath_rewriting(): | |||
| def build_config(schema_dir): | |||
| return mock.Mock( | |||
| registry=get_registry({ | |||
| 'swagger_schema': compile_swagger_schema(schema_dir), | |||
| 'swagger_schema': validate_swagger_schema(schema_dir), | |||
| }) | |||
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.
I don't think this is right validate_swagger_schema doesn't return anything. This should still be compile_swagger_schema.
pyramid_swagger should still return the same exceptions, we probably just want to wrap the exception
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.
Oh correct. I was testing my validation spec here which was wrong. I have reverted back these changes, and added similar tests in spec_test.py which get validated through swagger_spec_validator.
|
This mostly lgtm, but I think the test changes show that we actually need to wrap some exceptions. Users should expect the same exceptions out of |
swagger_spec_validator. This commit only covers validation of swagger 2.0 spec and in no way handles serving of 2.0 compatible endpoint. It currently breaks py33 and py34 tests. This should be rectified with the merge of Yelp/swagger_spec_validator#11.
|
Changes Unknown when pulling 94c50a3 on prat0318:introduce_ssv into * on striglia:master*. |
|
Currently the possible exposed exceptions are |
|
Yeah I'd focus on backwards compatibility right now, but keep in mind we're free to have more descriptive exceptions once we do a breaking change. My guess is users won't find distinct exception classes for the various "your spec is invalid" exceptions all that useful....we can probably just use one consistent exception and different messages. |
|
This patch is BC, except that |
1 similar comment
|
Yeah let's wrap it up to maintain backwards compatibility. I don't mind if exception msg changes, but the class should be consistent. You are free to modify the message to make it clear what is going wrong. |
|
Made the change BC by wrapping the ssv's error with |
|
|
|
That subtle difference is probably fine. I want to revamp these errors in 2.0.0 but for now we'll let it slide. Looks good aside from the CI build passing. |
pyramid_swagger/exceptions.py
Outdated
| @@ -8,3 +11,12 @@ class RequestValidationError(HTTPClientError): | |||
|
|
|||
| class ResponseValidationError(HTTPInternalServerError): | |||
| pass | |||
|
|
|||
|
|
|||
| def wrap_exception(method): | |||
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.
One thought: let's name this specifically or pass in the exception to reraise as.
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.
Good idea. i will pass the exception to reraise as an arg.
|
+1 "we can probably just use one consistent exception and different messages." |
pyramid_swagger/spec.py
Outdated
| 'No swagger spec found in directory:{0}. Note that your json file ' | ||
| 'must be named {1} or {2}'.format( | ||
| schema_dir, SWAGGER_2DOT0_FILENAME, API_DOCS_FILENAME)) | ||
|
|
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.
Possible to remove the else stmt.
if x:
return swagger20_filepath
if y:
return swagger12_filepath
raise swagger_spec_validator.SwaggerValidationError(...)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.
ack.
…r to maintain backwards compatiblity.
|
@prat0318 is this ready or still in progress? |
|
This is kind of blocked on the |
|
Yeah, blocked specifically on python-jsonschema/jsonschema#203 getting merged. |
|
|
…roduce_ssv Conflicts: pyramid_swagger/__init__.py pyramid_swagger/ingest.py pyramid_swagger/spec.py tests/api_test.py tests/includeme_test.py
|
|
| @@ -14,7 +14,8 @@ | |||
| { | |||
| "paramType": "query", | |||
| "name": "content", | |||
| "required": true | |||
| "required": true, | |||
| "type": "string" | |||
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.
type: string was added as jsonschema was flaking with no type present error instead of intended nickname not present error.
…gger_spec_validator
|
|
1 similar comment
| @@ -16,6 +16,7 @@ | |||
|
|
|||
|
|
|||
| EXTENDED_TYPES = { | |||
| 'number': (float,), | |||
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.
'float': (float) expected the param type to be 'float', which was not as per swagger spec 1.2 (the format can be float, not the type).
pyramid_swagger/exceptions.py
Outdated
| import sys | ||
|
|
||
| import six | ||
|
|
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.
no blank line since six and pyramid are both 3rd party
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.
Ack.
|
Fix-n-ship |
2 similar comments
|
|
1 similar comment
|
|
|
Looks good! |
Delegate spec validation to `swagger_spec_validator`.
Fixes #81. This commit delegates swagger validation to py package
swagger_spec_validator. This commit only covers the validation part ofswagger 1.2/2.0 spec and in no way handles the serving of 2.0 compatible endpoint.
It currently breaks py33 and py34 tests. This should be rectified with
the merge of Yelp/swagger_spec_validator#11.
Another change made is regarding the swagger spec file convention between 1.2 and 2.0.
Validation check first tries to find Swagger 2.0 spec (which should be just a single file, named,
swagger.json) otherwise it tries to find Swagger 1.2 spec.swagger_spec_validatorreads the spec again to decide whether the spec is a 1.2 or a 2.0. I am checking these here because, convention wise,api_docs.jsonis not a correct name for a2.0swagger schema. More such changes would need to be made whenpyramid_swaggerhandles2.0schema completely.