diff --git a/adapters/humabunrouter/humabunrouter.go b/adapters/humabunrouter/humabunrouter.go index 8fb1cdca..66c6e86b 100644 --- a/adapters/humabunrouter/humabunrouter.go +++ b/adapters/humabunrouter/humabunrouter.go @@ -34,6 +34,10 @@ func (c *bunContext) Operation() *huma.Operation { return c.op } +func (c *bunContext) WrappedContext() interface{} { + return c.r +} + func (c *bunContext) Context() context.Context { return c.r.Context() } diff --git a/adapters/humachi/humachi.go b/adapters/humachi/humachi.go index 2f4be07c..db690101 100644 --- a/adapters/humachi/humachi.go +++ b/adapters/humachi/humachi.go @@ -32,6 +32,10 @@ func (c *chiContext) Operation() *huma.Operation { return c.op } +func (c *chiContext) WrappedContext() interface{} { + return c.r +} + func (c *chiContext) Context() context.Context { return c.r.Context() } diff --git a/adapters/humaecho/humaecho.go b/adapters/humaecho/humaecho.go index ece42e73..a1f1430c 100644 --- a/adapters/humaecho/humaecho.go +++ b/adapters/humaecho/humaecho.go @@ -31,6 +31,10 @@ func (c *echoCtx) Operation() *huma.Operation { return c.op } +func (c *echoCtx) WrappedContext() interface{} { + return c.orig +} + func (c *echoCtx) Context() context.Context { return c.orig.Request().Context() } diff --git a/adapters/humafiber/humafiber.go b/adapters/humafiber/humafiber.go index 3ca99f91..2588f128 100644 --- a/adapters/humafiber/humafiber.go +++ b/adapters/humafiber/humafiber.go @@ -61,6 +61,10 @@ func (c *fiberCtx) Matched() string { return c.orig.Route().Path } +func (c *fiberCtx) WrappedContext() interface{} { + return c.orig +} + func (c *fiberCtx) Context() context.Context { return &contextAdapter{ Ctx: c.orig, diff --git a/adapters/humaflow/humaflow.go b/adapters/humaflow/humaflow.go index d4d5452a..2c139297 100644 --- a/adapters/humaflow/humaflow.go +++ b/adapters/humaflow/humaflow.go @@ -30,6 +30,10 @@ func (c *goContext) Operation() *huma.Operation { return c.op } +func (c *goContext) WrappedContext() interface{} { + return c.r +} + func (c *goContext) Context() context.Context { return c.r.Context() } diff --git a/adapters/humagin/humagin.go b/adapters/humagin/humagin.go index 64762cc4..16f4f1ba 100644 --- a/adapters/humagin/humagin.go +++ b/adapters/humagin/humagin.go @@ -31,6 +31,10 @@ func (c *ginCtx) Operation() *huma.Operation { return c.op } +func (c *ginCtx) WrappedContext() interface{} { + return c.orig +} + func (c *ginCtx) Context() context.Context { return c.orig.Request.Context() } diff --git a/adapters/humago/humago.go b/adapters/humago/humago.go index 41b23ba9..b3d5b0f9 100644 --- a/adapters/humago/humago.go +++ b/adapters/humago/humago.go @@ -32,6 +32,10 @@ func (c *goContext) Operation() *huma.Operation { return c.op } +func (c *goContext) WrappedContext() interface{} { + return c.r +} + func (c *goContext) Context() context.Context { return c.r.Context() } diff --git a/adapters/humahttprouter/humahttprouter.go b/adapters/humahttprouter/humahttprouter.go index 56730423..4ae06a99 100644 --- a/adapters/humahttprouter/humahttprouter.go +++ b/adapters/humahttprouter/humahttprouter.go @@ -34,6 +34,10 @@ func (c *httprouterContext) Operation() *huma.Operation { return c.op } +func (c *httprouterContext) WrappedContext() interface{} { + return c.r +} + func (c *httprouterContext) Context() context.Context { return c.r.Context() } diff --git a/adapters/humamux/humamux.go b/adapters/humamux/humamux.go index 7525b43d..cbf0842a 100644 --- a/adapters/humamux/humamux.go +++ b/adapters/humamux/humamux.go @@ -32,6 +32,10 @@ func (c *gmuxContext) Operation() *huma.Operation { return c.op } +func (c *gmuxContext) WrappedContext() interface{} { + return c.r +} + func (c *gmuxContext) Context() context.Context { return c.r.Context() } diff --git a/api.go b/api.go index a49a9314..bad6a4c3 100644 --- a/api.go +++ b/api.go @@ -64,6 +64,12 @@ type Context interface { // Operation returns the OpenAPI operation that matched the request. Operation() *Operation + // WrappedContext returns the underlying Adapter original + // Request context. For example, `*http.Request` for the `http` adapter. + // This is useful for accessing router-specific information and + // transitioning existing handler functionality. + WrappedContext() interface{} + // Context returns the underlying request context. Context() context.Context