Skip to content

Comments

fix(openapi): correct response validation for falsy objects#7990

Open
amin-farjadi wants to merge 3 commits intoaws-powertools:developfrom
amin-farjadi:fix/incorrect-falsy-validation
Open

fix(openapi): correct response validation for falsy objects#7990
amin-farjadi wants to merge 3 commits intoaws-powertools:developfrom
amin-farjadi:fix/incorrect-falsy-validation

Conversation

@amin-farjadi
Copy link
Contributor

@amin-farjadi amin-farjadi commented Feb 10, 2026

Issue number: closes #5887

Summary

Fix openapi response validation behaviour on Falsy return objects.

Changes

in openapi_validation.py, OpenAPIResponseValidationMiddleware class:

  • behaviour of _handle_response method modified
  • behaviour of _serialize_response method modified
  • _serialize_response method renamed to _serialize_response_with_validation

in test_openapi_validation_middleware.py:

in test_http_resolver_pydantic.py:

  • test_async_handler_with_validation marked to skip due to a separate issue

User 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.

@amin-farjadi amin-farjadi requested a review from a team as a code owner February 10, 2026 09:27
@amin-farjadi amin-farjadi requested a review from sdangol February 10, 2026 09:27
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 10, 2026
@github-actions github-actions bot added the bug Something isn't working label Feb 10, 2026
@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.63%. Comparing base (c4434b7) to head (6466bbf).

Files with missing lines Patch % Lines
...ls/event_handler/middlewares/openapi_validation.py 88.88% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@amin-farjadi
Copy link
Contributor Author

Hi @leandrodamascena is there anything I can do for this?

Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@dreamorosi dreamorosi removed the request for review from sdangol February 25, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working event_handlers size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Open API Validation not validating response serialization when body is Falsy.

3 participants