-
-
Notifications
You must be signed in to change notification settings - Fork 135
Integrate Requests library #24
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
…n library to openapi-core
…on library to openapi-core
Codecov Report
@@ Coverage Diff @@
## master #24 +/- ##
==========================================
- Coverage 98.55% 97.14% -1.41%
==========================================
Files 18 18
Lines 897 946 +49
==========================================
+ Hits 884 919 +35
- Misses 13 27 +14
Continue to review full report at Codecov.
|
|
||
@property | ||
def path_pattern(self): | ||
return self.url.path |
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 your implementation for the path_pattern is going to work for routes that have path parameters. The library does a dictionary lookup where it expects the path_pattern to equal the path in the spec. For example, consider the path '/pets/{petId}'. Your implementation will cause the library to try to look up something like '/pets/123' in the paths dict, which will cause the validation to fail because that's not the way the path is defined in the OAS 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.
I'll be pushing a PR sometime today that should deal with the path_pattern problem. If accepted then your implementation will likely work correctly with my addition.
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.
Actually, it's more complicated than I thought. I have something that would work for the path_pattern but it doesn't account for the path and query parameters.
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.
Yes, if we have route pattern, this would not work. I think we should add route pattern when creating RequestsOpenAPIRequest object:
openapi_request = RequestsOpenAPIRequest(req, url_pattern='/pets/{petId}')
Currently I am working on it, could not say when it would ready...
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'm wondering if this should actually be a part of the library. Consider this.
We already have a regex-like pattern in the route:
/pets/{petId})
If we convert this into a true regex then we should be able to match against every possible pattern that this path can have:
/pets/(.*)
It makes sense to do this in the spec object rather than the request object because the spec contains the patterns of every possible path in the API. Thus we merely match the url against all possible paths, which is O(n) though n should be small, and pick the pattern that matches the raw url.
The problem then (and this is where I am at the moment) is that we must also extract the path path and query parameters. The query params should be able to be parsed easily. The path params require a bit more work since this is part of the validators, but it's definitely doable.
A second option is to pass the spec to the request object and let it figure out everything there. However, I feel it would be far more user friendly to simply be able to have the core library extract this information from a simpler request object since there are plenty or url parsing tools and it would make implementing request wrappers much easier in the future.
@andyceo thanks for the contribution. The feature looks very useful. We still need tests though. |
I create a script for testing API of our node. Curremtly I skip routes with url patterns, found interesting fatal error for
Discovering what is wrong. I am testing this API: https://github.com/ergoplatform/ergo/blob/master/src/main/resources/api/openapi.yaml |
…rrectly calculated from request
Make commit with bugfix for message above. Update Pull Request description. |
…Request.mimetype properties
Complete RequestsOpenAPIRequest object properties body and mimetype. Change PR head message respectively. |
Closing in favor of #209 |
Hi!
Thank you for your great lib!
I would like to propose integration with Requests, another great python library.
Sometimes I have an API given on another language, and all I have to do is to generate Requests objects based on given opeapi.yaml file and check API Responses. I want to use your lib and thats why I can not or does not want use Flask.
Usage scenario is something like this:
Repeat the above for all endpoints in paths in openapi.yaml.