@@ -138,6 +138,11 @@ func (c *gmuxContext) BodyWriter() io.Writer {
138138 return c .w
139139}
140140
141+ // NewContext creates a new Huma context from an HTTP request and response.
142+ func NewContext (op * huma.Operation , r * http.Request , w http.ResponseWriter ) huma.Context {
143+ return & gmuxContext {op : op , r : r , w : w }
144+ }
145+
141146type gMux struct {
142147 options
143148 router * mux.Router
@@ -149,7 +154,7 @@ func (a *gMux) Handle(op *huma.Operation, handler func(huma.Context)) {
149154 Path (op .Path ).
150155 Methods (op .Method ).
151156 HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
152- handler (& gmuxContext { op : op , r : r , w : w } )
157+ handler (NewContext ( op , r , w ) )
153158 })
154159 if a .routeCustomizer != nil {
155160 a .routeCustomizer (op , route )
@@ -160,6 +165,11 @@ func (a *gMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
160165 a .router .ServeHTTP (w , r )
161166}
162167
168+ // NewAdapter creates a new adapter for the given Gorilla mux.
169+ func NewAdapter (r * mux.Router , options ... Option ) huma.Adapter {
170+ return & gMux {router : r , options : parseOptions (options )}
171+ }
172+
163173func New (r * mux.Router , config huma.Config , options ... Option ) huma.API {
164- return huma .NewAPI (config , & gMux { router : r , options : parseOptions ( options )} )
174+ return huma .NewAPI (config , NewAdapter ( r , options ... ) )
165175}
0 commit comments