Overview
Sponsors
Big shout out to our new sponsors. Thank you so much! ❤️
Better Support For Recursive Structs
Request/response bodies now have better support for recursive data structures, for example:
type Node struct {
Value string `json:"value"`
Left *Node `json:"left,omitempty"`
Right *Node `json:"right,omitempty"`
}Multipart Form Support
You can now more easily access the incoming request's multipart form via the RawBody field:
huma.Register(api, huma.Operation{
OperationID: "upload-files",
Method: http.MethodPost,
Path: "/upload",
Summary: "Example to upload a file",
}, func(ctx context.Context, input struct {
RawBody multipart.Form
}) (*struct{}, error) {
// Process multipart form here.
return nil, nil
})https://huma.rocks/features/request-inputs/#multipart-form-data
Body Fields Can Be Hidden
You can now hide body fields just like you could e.g. query/header params.
type MyObject struct {
Public string `json:"public"`
Private string `json:"private" hidden:"true"`
}This is useful if you want the field hidden from the docs but still serialized on the wire, so json:"-" would be inappropriate.
Type Aliases
Besides huma.SchemaProvider, you can now override schema generation behavior by registering known types with aliases, making it possible to override types used in structs from other packages.
registry := huma.NewMapRegistry("#/components/schemas", huma.DefaultSchemaNamer)
registry.RegisterTypeAlias(reflect.TypeFor[some_external_pkg.OptionalStr](), reflect.TypeFor[string]())
registry.RegisterTypeAlias(reflect.TypeFor[some_external_pkg.OptionalDateTime](), reflect.TypeFor[time.Time]())What's Changed
- feat: breaks infinite cycle when looking for fields in recursive structures. by @yuridevx in #306
- Multipart Form RawBody Type Support by @jamelt in #324
- feat: hidden body field support by @bekabaz in #328
- fix: allow multipart with body; prevent double status by @danielgtaylor in #329
- Allow specifying type aliases to provide schema definitions by @lsdch in #330
New Contributors
- @yuridevx made their first contribution in #306
- @jamelt made their first contribution in #324
- @bekabaz made their first contribution in #328
- @lsdch made their first contribution in #330
Full Changelog: v2.9.0...v2.10.0