huma
huma copied to clipboard
feat: propagate context to adapters on WithContext
This PR introduces:
- :sparkles:
WithContextmethods to adapters' context for proper context propagation. This is then opportunistically used inhuma.WithContextto avoid the generalsubContext. - :sparkles:
middlewareconversion functions for each adapter
The new middleware functions in particular could be exported as utilities. If we do that, we could also deduplicate the new TestWithValueShouldPropagateContext into a single table-driven test across all adapters.
Enhancements to context propagation:
- Added
WithContextmethods to propagate context in router-specific context wrappers (bunContext,bunCompatContext,chiContext,echoCtx,fiberWrapper,ginCtx,goContext, andhttprouterContext). These methods create new instances of the context wrappers with the updated context. [1] [2] [3] [4] [5] [6] [7] [8]
Middleware handling improvements:
- Added middleware conversion functions for all router adapters (
bunrouter,chi,echo,fiber,gin,go, andhttprouter). These functions wrap router-specific middleware into the Huma middleware format, enabling seamless integration. [1] [2] [3] [4] [5] [6]
Testing and validation:
- Introduced new test cases to verify context propagation using the
WithContextmethod and middleware functionality for each router adapter. These tests ensure that context values are correctly passed through middleware layers and accessible in handlers. [1] [2] [3] [4] [5] [6]
Closes #859
Codecov Report
Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
Project coverage is 92.50%. Comparing base (
df27bef) to head (6ef5c50). Report is 2 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| api.go | 0.00% | 2 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #867 +/- ##
==========================================
- Coverage 92.56% 92.50% -0.06%
==========================================
Files 23 23
Lines 5511 5514 +3
==========================================
Hits 5101 5101
- Misses 351 353 +2
- Partials 59 60 +1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.