fix(openapi): correct response validation for falsy objects#7990
fix(openapi): correct response validation for falsy objects#7990amin-farjadi wants to merge 3 commits intoaws-powertools:developfrom
Conversation
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7990 +/- ##
===========================================
- Coverage 96.73% 96.63% -0.10%
===========================================
Files 278 278
Lines 13654 13656 +2
Branches 1086 1086
===========================================
- Hits 13208 13197 -11
- Misses 327 338 +11
- Partials 119 121 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi @leandrodamascena is there anything I can do for this? |
dreamorosi
left a comment
There was a problem hiding this comment.
Thanks for the PR and for proposing a fix.
If I understand the issue correctly, this fix might be more complex than necessary.
The root cause is that falsy values are being skipped due to if response.body and response.is_json().
A minimal fix would be:
- if response.body and response.is_json():
+ if response.is_json():This single line change should fix both issues without more significant changes.
Do you think we could simplify the approach?



Issue number: closes #5887
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 additional scenariosin
test_http_resolver_pydantic.py:test_async_handler_with_validationmarked to skip due to a separate issueUser 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.