You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(event_handler): split OpenAPI validation to respect middleware returns - #7050
Fixes middleware validation issues by splitting OpenAPI validation into separate request and response validation middlewares.
Changes
New Middleware Architecture
Split the OpenAPIValidationMiddleware into two separate middlewares:
OpenAPIRequestValidationMiddleware - Validates incoming requests only
OpenAPIResponseValidationMiddleware - Validates outgoing responses only
Execution Order
┌─────────────────────────────────────────────────────────────────┐
│ Request Flow │
├─────────────────────────────────────────────────────────────────┤
│ 1. Request Validation Middleware │
│ ├─ Validates path params, query params, headers, body │
│ ├─ If invalid → Returns 422, stops execution │
│ └─ If valid → Continues to next middleware │
│ │
│ 2. User Middlewares (in order of registration) │
│ ├─ Auth middleware │
│ ├─ Rate limiting middleware │
│ ├─ Logging middleware │
│ ├─ etc... │
│ └─ Can return early responses (401, 403, 429, etc.) │
│ │
│ 3. Response Validation Middleware │
│ ├─ Only executes if reached (no early returns) │
│ └─ Validates response against OpenAPI schema │
│ │
│ 4. Route Handler │
│ └─ The actual endpoint function │
└─────────────────────────────────────────────────────────────────┘
User experience
Breaking change consideration
⚠️ Potential Impact: This fix may affect customers who were working around the previous incorrect behavior by catching RequestValidationError exceptions from middleware responses. However, this was unintended behavior that needed to be corrected.
Why this change is necessary:
The previous behavior was a bug - middleware responses should not be validated against OpenAPI schemas
Middleware responses (401, 403, 429) are control flow responses, not data responses
The fix aligns with expected middleware behavior patterns
Continuing the incorrect behavior would prevent proper middleware functionality
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Issue number: #5228
Discussion: #4656
Summary
Fixes middleware validation issues by splitting OpenAPI validation into separate request and response validation middlewares.
Changes
New Middleware Architecture
Split the
OpenAPIValidationMiddlewareinto two separate middlewares:OpenAPIRequestValidationMiddleware- Validates incoming requests onlyOpenAPIResponseValidationMiddleware- Validates outgoing responses onlyExecution Order
User experience
Breaking change consideration
RequestValidationErrorexceptions from middleware responses. However, this was unintended behavior that needed to be corrected.Why this change is necessary:
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
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.