fix(openapi): correct response validation for falsy objects #7990
+100
−37
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.



Issue number: closes #5887, #6216
Summary
Fix openapi response validation behaviour on Falsy return objects.
Changes
in
openapi_validation.py,OpenAPIResponseValidationMiddlewareclass:_handle_responsemethod modified_serialize_responsemethod modified_serialize_responsemethod renamed to_serialize_response_with_validationin
test_openapi_validation_middleware.py:test_validation_error_none_returned_non_optional_typeto cover issue Bug: Open API Validation not validating response serialization when body is Falsy. #5887test_validation_error_different_list_returned_non_optional_typeandtest_validate_list_responseto cover Bug: Upgrade to 3.7.0 breaks List response validation in APIGatewayRestResolver #6216in
test_http_resolver_pydantic.py:test_async_handler_with_validationmarked to skip due to issue Bug(HttpResolverLocal): OpenAPIResponseValidationMiddleware is not working as intended #7981User experience
Now Falsy response will be validated againt the OpenAPI return field (is there is any).
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.