v2.32.0
Overview
HTTP HEAD Convenience Function
A convenience function was added for HTTP HEAD requests.
huma.Head(api, "/path", handler)
Stop HTML-Escaping JSON
HTTP API usage would rarely need to HTML-escape responses, so this default JSON marshaling behavior has been turned off. If you would like to keep the behavior, you can do so by modifying the huma.Config.Formats
map. For example, error messages are now more readable:
- Before:
expected number \u003e= 10
- After:
expected number >= 10
Better Integer Validation
A new validation check has been added to present a better error message to the user when an integer is required but a floating point value like 1.5
is passed in. This now results in an expected integer
message instead of a JSON unmarshal error.
Groups + Convenience Function Improvements
Groups and convenience functions like huma.Get
now play better together. Groups will regenerate the operation ID and operation summary iff those values were auto-generated and have not been modified. This works for groups of groups as well. The following are equivalent:
huma.Get(api, "/v1/users/", handler)
v1 := huma.NewGroup(api, "/v1")
users := huma.NewGroup(v1, "/users")
huma.Get(users, "/", handler)
fmt.Println(api.OpenAPI().Paths["/v1/users/"].Summary)
// Output: Get v1 users
If you prefer full control over the operation ID and summary, use huma.Register
instead. You can still use group operation modifiers and convenience modifiers which modify the operation ID and/or summary and, if modified, they will not get regenerated. You can also disable generation by changing or unsetting the operation's _convenience_id
and _convenience_summary
metadata fields which are added by convenience functions like huma.Get
/huma.Put
/etc.
What's Changed
- feat: adding the head method to the list of convenience wrappers by @hiddenmarten in #760
- docs: update sponsors by @danielgtaylor in #764
- fix: do not HTML escape JSON output by default by @danielgtaylor in #765
- docs: fix model validator docs by @danielgtaylor in #766
- fix: better integer validation checks by @danielgtaylor in #768
- feat: better group+convenience function interop by @danielgtaylor in #770
New Contributors
- @hiddenmarten made their first contribution in #760
Full Changelog: v2.31.0...v2.32.0