v2.19.0
Overview
Sponsors
A big thank you to our new sponsor:
Multipart Form File Metadata
It's now possible to get filename & size metadata information from multipart form files.
huma.Post(api, "/form-example", func(ctx context.Context, input *struct{
RawBody huma.MultipartFormFiles[struct {
HelloWorld huma.FormFile `form:"file" contentType:"text/plain" required:"true"`
}]
}) (*struct{}, error) {
fileData := input.RawBody.Data()
fmt.Println( fileData.HelloWorld.Filename)
fmt.Println( fileData.HelloWorld.Size)
}
Easier Custom Context When Testing
It's now easier to pass a custom context to operations in the test API. Instead of having to create a custom request with its own context and manually call the adapter you can now use the methods like GetCtx
instead of Get
.
_, api := humatest.New(t)
ctx := context.Background() // define your necessary context
resp := api.GetCtx(ctx, "/greeting/world") // provide it using the 'Ctx' suffixed methods
Exploded Query Params
It's now possible to use the OpenAPI explode
feature where query params are passed multiple times rather than using comma separated values.
huma.Get(api, "/example", func(ctx context.Context, input *struct{
Value []string `query:"value,explode"`
}) (*struct{}, error) {
fmt.Println(input.Value)
return nil, nil
})
You can then make requests like GET /example?value=foo&value=bar
.
Autopatch Schema Improvements
Autopatch now uses the PUT
schema (modified to all be optional) rather than just relying on an object
with any allowed properties, which improves documentation for users. This is automatic so there is no need to configure anything new.
Other Improvements
- Performance improvement by removing the response body from panics which could be very large.
- Fixes to min/max items schema generation when using arrays.
- Remove
slices
dependency to continue to support Go 1.20 until 1.23 is released (we will support the latest two major versions just like the Go project itself)
What's Changed
- fix: expose metadata of decoded multipart form files by @lsdch in #466
- Extend TestAPI interface to allow for custom context.Context by @coury-clark in #469
- Update README_CN.md by @Ivlyth in #477
- remove response body from panic message by @austincollinpena in #479
- fix(schema): proper array minItems, maxItems and doc reporting in generated schemas by @Grumpfy in #485
- fix: remove slices dependency to better support Go 1.20 by @danielgtaylor in #497
- Implement exploded query parameters by @csmarchbanks in #498
- Improvement Autopatch (adding a body) by @ScriptType in #496
- docs: add new sponsor by @danielgtaylor in #506
New Contributors
- @coury-clark made their first contribution in #469
- @Ivlyth made their first contribution in #477
- @Grumpfy made their first contribution in #485
- @csmarchbanks made their first contribution in #498
- @ScriptType made their first contribution in #496
Full Changelog: v2.18.0...v2.19.0