generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 468
feat(event-handler): add per-route validation support #7965
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
Open
oyiz-michael
wants to merge
9
commits into
aws-powertools:develop
Choose a base branch
from
oyiz-michael:feat/per-route-validation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(event-handler): add per-route validation support #7965
oyiz-michael
wants to merge
9
commits into
aws-powertools:develop
from
oyiz-michael:feat/per-route-validation
+460
−4
Conversation
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
…nd decorators - Add enable_validation parameter to Route class constructor - Update all route decorators to accept enable_validation parameter - Modify _build_middleware_stack to check route-level validation setting - Route-level setting overrides resolver-level when explicitly set - Maintains backwards compatibility (None inherits from resolver) Addresses aws-powertools#6983
…olver - Update all HTTP method decorators to accept enable_validation parameter - Pass enable_validation to parent class methods - Ensures type safety and consistency across all resolvers Addresses aws-powertools#6983
…ware chain - Update _run_middleware_chain_async to check route-level validation - Conditionally add validation middlewares based on effective setting - Supports async/await pattern with per-route validation control Addresses aws-powertools#6983
- Test explicit route-level enable_validation=True - Test disabling validation on specific routes when globally enabled - Test request body and response validation with per-route settings - Test inheritance behavior and mixed validation scenarios - Test Pydantic v2 compatibility - All tests passing with full coverage Addresses aws-powertools#6983
- Demonstrate incremental validation adoption for monolithic Lambda - Show validated routes inheriting global setting - Show legacy routes with enable_validation=False - Practical example for migration scenarios Addresses aws-powertools#6983
- Move type: ignore comment to function definition line - Properly suppress return type mismatch warning in test
Use same pattern as other validation tests in codebase
Use typing.cast instead of type: ignore comment to properly handle intentional type mismatch in validation error test. This satisfies both mypy and SonarCloud while maintaining test functionality.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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 #6983
Summary
Changes
This PR adds per-route enable_validation control to Event Handler, allowing routes to override the resolver-level validation setting. This enables incremental adoption of OpenAPI validation in large monolithic Lambda functions.
Implementation:
Added enable_validation parameter (bool | None) to the Route class
Updated all route decorators to accept enable_validation
Modified middleware stack builder to check route-level setting before resolver-level setting
Extended support to BedrockAgentResolver and async middleware chains
Route-level setting overrides resolver-level when explicitly set; None inherits from resolver
Fully backwards compatible - existing code works without changes
User experience
Before:
Users with large monolithic Lambdas couldn't adopt validation incrementally without migrating all endpoints at once, which is time-consuming and risky.
After:
This enables teams to:
Enable validation globally on the resolver
Selectively disable it for legacy routes not yet ready
Migrate routes incrementally at their own pace
Avoid breaking changes during gradual adoption
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.