Add form data validator for validation middleware#1595
Merged
RobbeSneyders merged 5 commits intomainfrom Nov 4, 2022
Merged
Conversation
RobbeSneyders
commented
Sep 24, 2022
| raise BadRequestProblem(detail=f"{exception.message}{error_path_msg}") | ||
|
|
||
| async def receive(self) -> t.Optional[t.MutableMapping[str, t.Any]]: | ||
| async def wrapped_receive(self) -> Receive: |
Member
Author
There was a problem hiding this comment.
I changed this so validation is not delayed until the stream is consumed by the application. I think it makes sense for connexion to always validate the body (for certain content types), independent on if it's read in the application or not. This also makes it easier to follow / debug validation, and prevents further middlewares / application logic from being executed for an invalid request.
92857d0 to
0f742a5
Compare
0f742a5 to
008e12a
Compare
008e12a to
5585cb2
Compare
Pull Request Test Coverage Report for Build 3392925032
💛 - Coveralls |
Add python-multipart dependency to setup.py Copy validator map so it remains unchanged
d7be708 to
5bf97c2
Compare
* Move Swagger 2 form validation to middleware * Add unit test for form transformation
* Create MediaTypeDict class for range matching * Extract parsing instead of using jsonifier * Add default validator class as parameter defaults * Clean up form validation
5bf97c2 to
a1b1f53
Compare
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR moves form data validation to the middleware, which is quite complex due to differences between Swagger 2 and OpenAPI 3 in how form data is represented.
For OpenAPI 3, this is quite simple. The form data is represented as an object in the request body, which means we can just use a request body validator.
For Swagger 2, this is more complicated. The form data is represented as parameters instead. I see two options here:
This PR implements option 2.
Some open points still to address with the request body validator in this PR:
strict_validation, which makes less sense for OpenAPI 3 form validation, as this can now be controlled byadditionalPropertiesin the schema.instead.