Skip to content

Conversation

@prat0318
Copy link
Contributor

@prat0318 prat0318 commented Mar 3, 2015

Fixes #81. This commit delegates swagger validation to py package
swagger_spec_validator. This commit only covers the validation part of
swagger 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_validator reads 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.json is not a correct name for a 2.0 swagger schema. More such changes would need to be made when pyramid_swagger handles 2.0 schema completely.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8b90e1a on prat0318:introduce_ssv into * on striglia:master*.

@@ -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),
})
Copy link
Contributor

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

Copy link
Contributor Author

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.

@dnephin
Copy link
Contributor

dnephin commented Mar 3, 2015

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 pyramid_swagger.

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.
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 94c50a3 on prat0318:introduce_ssv into * on striglia:master*.

@prat0318
Copy link
Contributor Author

prat0318 commented Mar 3, 2015

Currently the possible exposed exceptions are ResourceListingNotFoundError, ApiDeclarationNotFoundError and SwaggerValidationError. Either we can use the third one to wrap the first two, or wrap ssv's SwaggerValidationError to some pyramid_swagger's SwaggerValidationError. I will create a separate issue to track it.

@striglia
Copy link
Contributor

striglia commented Mar 3, 2015

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.

@prat0318
Copy link
Contributor Author

prat0318 commented Mar 3, 2015

This patch is BC, except that jsonschema.ValidationError error thrown is now been replaced with swagger_spec_validator.SwaggerValidationError. Do we want to wrap the later error with the former for this patch to maintain BC?

@landscape-bot
Copy link

Code Health
Code quality remained the same when pulling 94c50a3 on prat0318:introduce_ssv into 425fcfa on striglia:master.

1 similar comment
@landscape-bot
Copy link

Code Health
Code quality remained the same when pulling 94c50a3 on prat0318:introduce_ssv into 425fcfa on striglia:master.

@striglia
Copy link
Contributor

striglia commented Mar 4, 2015

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.

@prat0318
Copy link
Contributor Author

prat0318 commented Mar 4, 2015

Made the change BC by wrapping the ssv's error with jsonschema's ValidationError. A subtle difference still remains is that if a resource_listing file is not present in the schema_dir, earlier IOError was thrown, but now jsonschema's ValidationError will be thrown (as all ssv's exceptions are wrapped under ValidationError), but i don't think that will be a showstopper.

@landscape-bot
Copy link

Code Health
Repository health decreased by 0.07% when pulling b68dd8e on prat0318:introduce_ssv into 425fcfa on striglia:master.

@striglia
Copy link
Contributor

striglia commented Mar 4, 2015

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.

@@ -8,3 +11,12 @@ class RequestValidationError(HTTPClientError):

class ResponseValidationError(HTTPInternalServerError):
pass


def wrap_exception(method):
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@analogue
Copy link
Contributor

analogue commented Mar 6, 2015

+1 "we can probably just use one consistent exception and different messages."

'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))

Copy link
Contributor

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(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack.

@striglia
Copy link
Contributor

@prat0318 is this ready or still in progress?

@dnephin
Copy link
Contributor

dnephin commented Mar 26, 2015

This is kind of blocked on the jsonschema changes as well, to fix the py3 errors.

@prat0318
Copy link
Contributor Author

Yeah, blocked specifically on python-jsonschema/jsonschema#203 getting merged.

@landscape-bot
Copy link

Code Health
Repository health increased by 0.07% when pulling 07bb136 on prat0318:introduce_ssv into e57b344 on striglia:master.

…roduce_ssv

Conflicts:
	pyramid_swagger/__init__.py
	pyramid_swagger/ingest.py
	pyramid_swagger/spec.py
	tests/api_test.py
	tests/includeme_test.py
@landscape-bot
Copy link

Code Health
Repository health decreased by 0.23% when pulling 068f4cb on prat0318:introduce_ssv into fe3b877 on striglia:master.

@@ -14,7 +14,8 @@
{
"paramType": "query",
"name": "content",
"required": true
"required": true,
"type": "string"
Copy link
Contributor Author

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.

@landscape-bot
Copy link

Code Health
Repository health decreased by 0.23% when pulling bda97cd on prat0318:introduce_ssv into fe3b877 on striglia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 99.72% when pulling bda97cd on prat0318:introduce_ssv into fe3b877 on striglia:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 99.72% when pulling bda97cd on prat0318:introduce_ssv into fe3b877 on striglia:master.

@@ -16,6 +16,7 @@


EXTENDED_TYPES = {
'number': (float,),
Copy link
Contributor Author

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).

@prat0318
Copy link
Contributor Author

@dnephin @analogue there were few merge conflicts with master, which i resolved. There is a float correction and sample tests spec correction as well in this commit. lmk if it looks good to merge.

import sys

import six

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@analogue
Copy link
Contributor

Fix-n-ship

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 99.72% when pulling 092e095 on prat0318:introduce_ssv into fe3b877 on striglia:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 99.72% when pulling 092e095 on prat0318:introduce_ssv into fe3b877 on striglia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) to 99.72% when pulling 092e095 on prat0318:introduce_ssv into fe3b877 on striglia:master.

@landscape-bot
Copy link

Code Health
Repository health decreased by 0.22% when pulling 092e095 on prat0318:introduce_ssv into fe3b877 on striglia:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0%) to 99.72% when pulling 9f0cfe7 on prat0318:introduce_ssv into fe3b877 on striglia:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0%) to 99.72% when pulling 9f0cfe7 on prat0318:introduce_ssv into fe3b877 on striglia:master.

@landscape-bot
Copy link

Code Health
Repository health decreased by 0.29% when pulling 9f0cfe7 on prat0318:introduce_ssv into fe3b877 on striglia:master.

@dnephin
Copy link
Contributor

dnephin commented Apr 27, 2015

Looks good!

dnephin added a commit that referenced this pull request Apr 27, 2015
Delegate spec validation to `swagger_spec_validator`.
@dnephin dnephin merged commit d218f96 into Yelp:master Apr 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delegate json schema validation to swagger_spec_validator.

6 participants