v2.25.0
Overview
Case-insensitive JSON
Since the standard library Go unmarshaler supports case-insensitive field matches, Huma has been updated to support this during validation as well to better support integration with legacy systems & clients. This behavior can be disabled by explicitly setting huma.ValidateStrictCasing = true
(the default matches the standard library behavior). For example, given:
huma.Put(api, "/demo", func(ctx context.Context, input *struct{
Body struct {
Value string `json:"value"`
}
}) (*struct{}, error) {
fmt.Println("Value is", input.Body.Value)
return nil, nil
})
If a client were to send {"Value": "test"}
instead of {"value": "test"}
it will now pass validation and work. This also works for the built-in CBOR format as well.
Support Scalar Pointers with Defaults
Defaults have become more useful by enabling the use of pointers for basic types to have default values attached. For example, given this input to an operation:
type MyInput struct {
Body struct {
Enabled *bool `json:"enabled,omitempty" default:"true"`
}
}
It's now possible to explicitly send false
without the value being overridden by the default. The behavior seen by the handler code is this:
Client sends | Handler sees |
---|---|
true |
true |
false |
false |
null / undefined |
true |
Since this is using the built-in mechanism to determine if a value was sent, there is no additional performance penalty for setting the default values in Huma.
What's Changed
- Update request-resolvers.md by @alexanderilyin in #619
- docs: fix YAML command example by @danielgtaylor in #624
- feat: case-insensitive field matching for JSON/CBOR by @danielgtaylor in #629
- feat: allow scalar pointers with defaults by @danielgtaylor in #633
- Update build-sdk.sh by @MaximeWeyl in #637
New Contributors
- @MaximeWeyl made their first contribution in #637
Full Changelog: v2.24.0...v2.25.0