Operation Handlers are used in Huma to modify an operation before registration.
type OperationHandler func(op *huma.Operation)
Normally, they are passed to huma.Get()
, huma.Post()
, etc. functions as the last arguments.
With hureg
you still can use them as usual, but you can also add them to the APIGen
instance to apply
them to all operations registered with this instance.
derivedApi := api.AddOpHandler(oh1, oh2)
When you do so, oh1
and oh2
will be converted to Registration Middlewares
and added to the new APIGen
instance.
Normally, you don't need the full power of Registration Middlewares and can use Operation Handlers for most of the cases where you need to modify an operation before registration but don't need to perform multiple registration or prevent registration at all.
The library provides the most commonly needed Operation Handlers in the
op_handlers
package.