v2.17.0
Overview
Convenience Method Operation Modifiers
You can now add modifier functions when registering operations using convenience methods like huma.Get
:
func OperationTags(tags ...string) func(o *Operation) {
return func(o *Operation) {
o.Tags = tags
}
}
huma.Get(api, "/demo", myHandler, OperationTags("one", "two"))
Use this to build out whatever functionality you need to simplify registration. These can also be composed & joined easily to give a concise way to register operations without falling back to huma.Register
directly.
Request Remote Address Access
It's now possible to access the requests's RemoteAddr
field through huma.Context
for use in middleware and/or resolvers, which works with all routers:
func MyMiddleware(ctx huma.Context, next func(huma.Context)) {
fmt.Println("Request address", ctx.RemoteAddr())
next(ctx)
}
Fix Unmarshaling of Embedded Body
Unmarshaling of embedded structs with a body field now works as expected:
type BodyContainer struct {
Body struct {
Name string `json:"name"`
}
}
huma.Register(api, huma.Operation{
Method: http.MethodPost,
Path: "/body",
}, func(ctx context.Context, input *struct {
BodyContainer
}) (*struct{}, error) {
// Do something with `input.Body.Name`...
return nil, nil
})
What's Changed
- feat: convenience methods with operationHandlers by @fourcels in #434
- fix: race condition in CLI tests by @danielgtaylor in #436
- docs: add new sponsor and quote by @danielgtaylor in #437
- fix: unmarshaling of request body when using struct embedding by @lsdch in #440
- feat: add request remote address to context by @danielgtaylor in #447
New Contributors
Full Changelog: v2.16.0...v2.17.0