Skip to content

v2.10.0

Compare
Choose a tag to compare
@danielgtaylor danielgtaylor released this 25 Mar 15:51
· 157 commits to main since this release
38cf30c

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

Full Changelog: v2.9.0...v2.10.0