v2.8.0
Overview
CLI Package
The CLI functionality has been moved into its own package humacli
. The existing huma.NewCLI
call continues to work but is marked as deprecated and will be removed in a future release. This will be a small breaking change in the future but is necessary to fix a design mistake that impacts dependencies that cannot otherwise be resolved. Migrating is an easy find/replace:
huma.NewCLI
→humacli.New
huma.CLI
→humacli.CLI
huma.Hooks
→humacli.Hooks
huma.WithOptions
→humacli.WithOptions
If you want to ensure your code doesn't include anything from the existing CLI and Cobra functionality, use the humanewclipackage
build tag, e.g. go build -tags humanewclipackage
. You won't save much space but this can help for package auditing.
Convenience Summary
Convenience functions like huma.Get
, huma.Put
, etc now generate a human-readable summary of the operation using the path. For example, huma.Get(api, "/things/{id}", ...)
would generate a summary of Get things by id
.
Easier Context Values
Router-agnostic middleware has gotten a bit easier to write with the new huma.WithValue
and huma.WithContext
functions to return a wrapped Huma context with its underlying request context.Context
replaced. Use it like:
func MyMiddleware(ctx huma.Context, next func(huma.Context)) {
// Wrap the context to add a value.
ctx = huma.WithValue(ctx, "some-key", "some-value")
// Call the next middleware in the chain. This eventually calls the
// operation handler as well.
next(ctx)
}
What's Changed
- docs: remove experimental flag for Go 1.22+ by @danielgtaylor in #282
- docs: fix broken link by @danielgtaylor in #283
- feat: add convenience functions for summary by @xarunoba in #284
- feat: add WithContext and WithValue for setting context values by @danielgtaylor in #295
- fix: move CLI to its own package, deprecate huma.NewCLI by @danielgtaylor in #291
New Contributors
Full Changelog: v2.7.0...v2.8.0