v2.20.0
Overview
Sponsors
Thank you to Zuplo for sponsoring the project.
Fixed Validation Tags & Referenced Schemas
Sometimes schemas and schemas in references wound up getting overwritten with default values for validation like minimum
, maximum
, minLength
, maxLength
, as well as skipping calling TransformSchema
. This is now fixed to behave as expected by derefencing structs and only setting validation values when the tag is actually present.
Customizable Validation Errors
Validation errors are now completely customizable as globals in the library.
// Set a custom message for minimum validation failure.
huma.MsgExpectedMinimumNumber = "expected number bigger than or equal to %v"
You can also change the function used to format error messages via huma.ErrorFormatter
. This must be overwritten before generating any schemas, as the generated messages are cached at schema creation time.
var ErrorFormatter func(format string, a ...any) string = fmt.Sprintf
Nullable Slices
Due to the way nil
slices get encoded in Go as null
in JSON and other formats, we now generate array schemas as nullable by default. See also the discussion and links to JSON v2 at golang/go#37711.
What's Changed
- fix(schema): proper minLength, maxLength in generated schemas. by @superstas in #513
- fix(schema): proper minimum, maximum in generated schemas. by @superstas in #515
- fix(schema): add dereferencing for SchemaFromType by @superstas in #518
- feat: add zuplo sponsorship by @danielgtaylor in #501
- docs: fix formatting in sponsors by @danielgtaylor in #523
- feat: make validation error messages customizable by @smacker in #520
- fix: nullable schemas for arrays/slices by @lsdch in #527
New Contributors
- @superstas made their first contribution in #513
- @smacker made their first contribution in #520
Full Changelog: v2.19.0...v2.20.0