v2.7.0
New Features
Convenience Functions
Convenience functions are available for common HTTP verbs, e.g. huma.Get
, huma.Post
, huma.Put
, etc. These provide less control over the OpenAPI generation, but are significantly less verbose than huma.Register
and make it easier to get started, provide quick examples/demos, and more.
huma.Get(api, "/demo", func(ctx context.Context, input *Input) (*Output, error) {
// ...
})
The OpenAPI operationId
field is generated from the path. The behavior can be modified by overriding huma.GenerateOperationID
if desired. It's easy to switch to huma.Register
at any time if/when you want to provide more information for the OpenAPI generation.
Custom Input Params
You can now use any type that supports encoding.TextUnmarshaler
as an input param (path/query/header/cookie). Combined with custom field schemas this is very powerful, and it can use custom request resolvers as well enabling better support for exhaustive error responses to clients. For example, the Google UUID library supports TextUnmarshaler
:
import "github.com/google/uuid"
type UUID struct {
uuid.UUID
}
func (UUID) Schema(r huma.Registry) *huma.Schema {
return &huma.Schema{Type: huma.TypeString, Format: "uuid"}
}
huma.Get(api, "/demo", func(ctx context.Context, input *struct{
Example UUID `query:"example"`
}) (*Output, error) {
// Print out the UUID time portion
fmt.Println(input.Example.Time())
})
What's Changed
- fix: set CLI name from executable, add docs for name/version by @danielgtaylor in #265
- fix: Set body height to 100% of the viewport height by @mailbaoer in #271
- feat: support input param types using
TextUnmarshaler
by @danielgtaylor in #276 - fix: allow response types to contain unexported fields by @FlorianLoch in #278
- feat: add convenience methods by @danielgtaylor in #279
- fix: return wrapped errors on transform or write failure by @danielgtaylor in #280
New Contributors
- @mailbaoer made their first contribution in #271
- @FlorianLoch made their first contribution in #278
Full Changelog: v2.6.0...v2.7.0