-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Add form data validator for validation middleware #1595
Conversation
@@ -56,7 +67,7 @@ def validate(self, body: dict): | |||
) | |||
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: |
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 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
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 byadditionalProperties
in the schema.instead.