danielgtaylor/huma
Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
π¦ Fiber v3
- This release adds support for Fiber v3. Dedicated v2 functions have been added to ensure support for both.
π What's Changed
- Fix header regression by @wolveix in https://github.com/danielgtaylor/huma/pull/1007
- feat(humafiber): add Fiber v3 support by @wheinze in https://github.com/danielgtaylor/huma/pull/962
- Accept empty base64 inputs by @wolveix in https://github.com/danielgtaylor/huma/pull/1013
- chore(deps): bump github.com/gofiber/fiber/v3 from 3.1.0 to 3.2.0 by @dependabot[bot] in https://github.com/danielgtaylor/huma/pull/1018
- Propagate underlying context to GET/PUT requests in the autopatch handler by @alixinne in https://github.com/danielgtaylor/huma/pull/1019
- chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.12 to 2.52.13 by @dependabot[bot] in https://github.com/danielgtaylor/huma/pull/1022
β¨ New Contributors
- @wheinze made their first contribution in https://github.com/danielgtaylor/huma/pull/962
- @alixinne made their first contribution in https://github.com/danielgtaylor/huma/pull/1019
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.37.3...v2.38.0
π¦ Overview
- This bugfix release fixes a few minor bugs and typos from previous releases.
- This also adjusts the HTTP status code returned by Huma if marshaling a response fails, from 200 to 500.
π What's Changed
- Fix: add allow-popups to CSP sandbox for OAuth popups by @Micaso in https://github.com/danielgtaylor/huma/pull/987
- Fix: use epsilon tolerance in multipleOf float validation by @smazurov in https://github.com/danielgtaylor/huma/pull/989
- Fix typo in groups.md documentation by @Its-Haze in https://github.com/danielgtaylor/huma/pull/995
- Fix relative schema urls by @wolveix in https://github.com/danielgtaylor/huma/pull/990
- Return HTTP 500 if marshaling fails by @wolveix in https://github.com/danielgtaylor/huma/pull/997
- Handle contentEncoding and contentMediaType keys by @NPellet in https://github.com/danielgtaylor/huma/pull/919
- Chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.11 to 2.52.12 by @dependabot[bot] in https://github.com/danielgtaylor/huma/pull/984
β¨ New Contributors
- @Micaso made their first contribution in https://github.com/danielgtaylor/huma/pull/987
- @smazurov made their first contribution in https://github.com/danielgtaylor/huma/pull/989
- @Its-Haze made their first contribution in https://github.com/danielgtaylor/huma/pull/995
- @NPellet made their first contribution in https://github.com/danielgtaylor/huma/pull/919
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.37.2...v2.37.3
π¦ Overview
- This bugfix release fixes an issue with how form data was being documented in OpenAPI.
- This also fixes embedded objects with valid JSON tags being incorrectly embedded in the OpenAPI docs.
π What's Changed
- Don't embed embedded objects with valid JSON tags by @wolveix in https://github.com/danielgtaylor/huma/pull/978
- Fix OpenAPI path prefix regression from $schema fix PR by @wolveix in https://github.com/danielgtaylor/huma/pull/979
- Fix form param doc regression by @wolveix in https://github.com/danielgtaylor/huma/pull/981
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.37.1...v2.37.2
π¦ Overview
- This bugfix release fixes an issue regarding the Swagger UI docs renderer, as well as fixes an issue preventing Groups from using the configurable options released in v2.37.1.
- This also brings interface constructors to `humamux`.
π What's Changed
- Export Gorilla Mux interface constructors by @RangelReale in https://github.com/danielgtaylor/huma/pull/965
- fix(api): use proper CSP hash for inline script in Swagger doc renderer by @leonklingele in https://github.com/danielgtaylor/huma/pull/977
- fix(group): ensure "Group" satisfies the configProvider interface by @leonklingele in https://github.com/danielgtaylor/huma/pull/976
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.37.0...v2.37.1
π¦ Operation ID Normalization
- Spaces in operation IDs get automatically converted to hyphens now.
π Optimizations & Fixed Memory Leak
- Various internal operations have been optimized (~7% overall improvement): https://github.com/danielgtaylor/huma/pull/973#issue-3960297052
- A memory leak when using `MultipartFormFiles` has been resolved.
β¨ New Configurable Options
- A new config option has been added to allow additional properties by default. This can be set in the API config.
- ```go
- config.AllowAdditionalPropertiesByDefault = true
- ```
- A new config option has been added to set fields to optional by default, rather than required by default. This can be set in the API config.
- ```go
- config.FieldsOptionalByDefault = true
- ```
- + 4 more
π¦ Framework & Dependency Updates
- Upgraded to Go 1.25
π What's Changed
- chore(registry): drop random suffix out of variable name by @leonklingele in https://github.com/danielgtaylor/huma/pull/972
- Implement Registry and Query Validation Options by @wolveix in https://github.com/danielgtaylor/huma/pull/925
- Resource optimizations, Go 1.25, remove IDNA library, add benchmark CI by @wolveix in https://github.com/danielgtaylor/huma/pull/973
- Additional docs + normalize operation IDs by @wolveix in https://github.com/danielgtaylor/huma/pull/974
- chore(api,docs): update unpkg libraries, specify SRI hash, add strict CSP by @leonklingele in https://github.com/danielgtaylor/huma/pull/916
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.36.0...v2.37.0
π¦ Overview
- This release is larger than usual. Key changes:
π¦ Unique Operation ID Enforcement
- Operation IDs are now enforced to be unique, preventing collisions in generated OpenAPI specs. (Fixes #910)
π¦ Expanded Content-Type Handling
- Graceful handling when clients omit `Content-Type` for non-JSON endpoints
- Support for charset definitions in `Content-Type` header
- Updated OpenAPI media types to align with newer standards
- Validation support for non-JSON request body content types
π¦ Form Handling Improvements
- Form data now required by default for clearer validation behavior
- Fixed panic when text value sent to `FormFile` field
π¦ Schema & Validation Enhancements
- Fixed `$schema` field reusing links for identical objects
- Fixed duplicate `example` rendering in some docs renderers
- Improved `$schema` URL handling (with docs for disabling it)
- Extended `netip.Addr` to support IPv6; added new `ip` format for v4/v6
- Fixed incorrect schema generation for arrays
π¦ Framework & Dependency Updates
- Fiber adapter now uses `Body()` instead of `BodyRaw()` for automatic decompression
- Upgraded to Go 1.24
π What's Changed
- Support Forcing Unique Operation IDs (Fixes #910) by @wolveix in https://github.com/danielgtaylor/huma/pull/937
- Support charset definitions in content type header by @wolveix in https://github.com/danielgtaylor/huma/pull/951
- chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.9 to 2.52.11 by @dependabot[bot] in https://github.com/danielgtaylor/huma/pull/955
- Fix various issues by @wolveix in https://github.com/danielgtaylor/huma/pull/961
- Require form data by default by @wolveix in https://github.com/danielgtaylor/huma/pull/963
- Fix: Support non-JSON content types for request body validation by @roidelapluie in https://github.com/danielgtaylor/huma/pull/926
- Allow empty content type from client by @wolveix in https://github.com/danielgtaylor/huma/pull/964
- Docs for disabling the $schema field by @wolveix in https://github.com/danielgtaylor/huma/pull/966
- + 7 more
β¨ New Contributors
- @roidelapluie made their first contribution in https://github.com/danielgtaylor/huma/pull/926
- @akkuman made their first contribution in https://github.com/danielgtaylor/huma/pull/928
- @domdomegg made their first contribution in https://github.com/danielgtaylor/huma/pull/899
- @alexisvisco made their first contribution in https://github.com/danielgtaylor/huma/pull/932
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.35.0...v2.36.0
π¦ Overview
- _Moved this release as it was incorrectly tagged as v2.34.3._
π¦ Improved Error Messaging for Form Pointers
- Pointer panic messages now explicitly include βFormβ where applicable, making debugging clearer and resolving #892.
π¦ Expanded String Format Support
- Added support for `duration` and `idn-hostname` string formats, improving schema expressiveness and validation coverage.
π What's Changed
- fix: include βFormβ in pointer panic message (fixes #892) by @wolveix in [https://github.com/danielgtaylor/huma/pull/938](https://github.com/danielgtaylor/huma/pull/938)
- feat: support duration and IDN-hostname string formats by @wolveix in [https://github.com/danielgtaylor/huma/pull/939](https://github.com/danielgtaylor/huma/pull/939)
- docs: add simple HTML docs by @wolveix in [https://github.com/danielgtaylor/huma/pull/941](https://github.com/danielgtaylor/huma/pull/941)
- fix: header parsing by @wolveix in [https://github.com/danielgtaylor/huma/pull/944](https://github.com/danielgtaylor/huma/pull/944)
- perf(schema): optimize convertType with fast paths for compatible types by @baagod in https://github.com/danielgtaylor/huma/pull/931
- Added exhaustive error code wrappers by @rhodeon in https://github.com/danielgtaylor/huma/pull/876
β¨ New Contributors
- @baagod made their first contribution in https://github.com/danielgtaylor/huma/pull/931
- @rhodeon made their first contribution in https://github.com/danielgtaylor/huma/pull/876
- Full Changelog: [https://github.com/danielgtaylor/huma/compare/v2.34.2...v2.34.3](https://github.com/danielgtaylor/huma/compare/v2.34.2...v2.35.0)
π¦ TLS-Aware URL Scheme Detection
- Huma now correctly uses the `https` URL scheme when TLS is configured, and `http` when it is not. Previously, the scheme detection could be incorrect in certain scenarios.
π Time Wrapper Parsing Fix
- Fixed an issue where time wrapper types failed to parse correctly, resolving #844.
π What's Changed
- fix: correct example format for tags in Pet struct by @vikyw89 in https://github.com/danielgtaylor/huma/pull/858
- docs: add links to hire me by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/869
- Revert "docs: add links to hire me" by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/890
- chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.7 to 2.52.9 by @dependabot[bot] in https://github.com/danielgtaylor/huma/pull/882
- Fix code samples in the response output documentation by @prnvbn in https://github.com/danielgtaylor/huma/pull/927
- fix: use "http" URL scheme only if no TLS is used by @leonklingele in https://github.com/danielgtaylor/huma/pull/905
- fix: failed to parse time wrapper, close #844 by @zhenzou in https://github.com/danielgtaylor/huma/pull/924
- Minor linting/formatting by @wolveix in https://github.com/danielgtaylor/huma/pull/936
β¨ New Contributors
- @vikyw89 made their first contribution in https://github.com/danielgtaylor/huma/pull/858
- @prnvbn made their first contribution in https://github.com/danielgtaylor/huma/pull/927
- @leonklingele made their first contribution in https://github.com/danielgtaylor/huma/pull/905
- @zhenzou made their first contribution in https://github.com/danielgtaylor/huma/pull/924
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.34.1...v2.34.2
π What's Changed
- fix: content type bug introduced in #850 by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/854
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.34.0...v2.34.1
π¦ Opt-in for 406 Errors
- ```go
- config := huma.DefaultConfig("My API", "1.0.0")
- config.NoFormatFallback = true
- ```
π What's Changed
- feat: #843 Allow 406 Not Acceptable with NoFormatFallback config by @jh125486 in https://github.com/danielgtaylor/huma/pull/850
β¨ New Contributors
- @jh125486 made their first contribution in https://github.com/danielgtaylor/huma/pull/850
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.33.0...v2.34.0
π¦ Minimum Go Version Upgrade
- Go 1.23+ is now required, keeping to the "last two versions" approach that Go itself uses for support. Dependencies have also been upgraded, including a few dependabots for security issues.
π¦ Explicitly Set Empty Example
- You can now explicitly set empty example strings:
- ```go
- type MyInput struct {
- MyField string `json:"my_field" example:""`
- }
- ```
π¦ Empty Group Path
- It's now possible to use operations on a group with an empty path, having the operation use the group's path without any additions:
- ```go
- grp := huma.NewGroup(api, "/users")
- huma.Get(grp, "", func(ctx context.Context, input *struct{}) (*struct{}, error) {
- return nil, nil
- })
- ```
π Adapter Context Unwrapping Fixes
- You can now use `huma.WithValue` and `huma.WithContext` to wrap a context and the adapter-specific `Unwrap` function will no longer panic.
- ```go
- subctx := huma.WithValue(ctx, key, "value")
- r, w := humago.Unwrap(subctx)
- ```
π¦ Nested CLI Options
- Nested CLI options via structs are now supported.
- ```go
- type DatabaseConfig struct {
- Host string `doc:"Database host"`
- Port int `doc:"Database port" default:"5432"`
- Username string `doc:"Database username"`
- }
- type AppConfig struct {
- + 5 more
π¦ Other
- Various other fixes and feature improvements. Thanks everyone!
π What's Changed
- fix: Allow explicitely setting the "example" tag to the empty string by @mumu1000 in https://github.com/danielgtaylor/huma/pull/773
- chore(docs): add link to IANA auth schemes by @costela in https://github.com/danielgtaylor/huma/pull/774
- minor: use ErrUnknownContentType in more places by @costela in https://github.com/danielgtaylor/huma/pull/799
- Fix panic when sending an empty file field in a form by @Supet1337 in https://github.com/danielgtaylor/huma/pull/785
- Add WithIndex to PathBuffer by @chrisguitarguy in https://github.com/danielgtaylor/huma/pull/788
- fix: make order of SSE events stable in openapi by @culli in https://github.com/danielgtaylor/huma/pull/806
- Allow empty path in group operations by @Serjlee in https://github.com/danielgtaylor/huma/pull/807
- feat: Go 1.23 minimum, modernize codebase by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/820
- + 16 more
β¨ New Contributors
- @mumu1000 made their first contribution in https://github.com/danielgtaylor/huma/pull/773
- @Supet1337 made their first contribution in https://github.com/danielgtaylor/huma/pull/785
- @chrisguitarguy made their first contribution in https://github.com/danielgtaylor/huma/pull/788
- @culli made their first contribution in https://github.com/danielgtaylor/huma/pull/806
- @Serjlee made their first contribution in https://github.com/danielgtaylor/huma/pull/807
- @RangelReale made their first contribution in https://github.com/danielgtaylor/huma/pull/810
- @betaprior made their first contribution in https://github.com/danielgtaylor/huma/pull/791
- @byronmurg made their first contribution in https://github.com/danielgtaylor/huma/pull/838
- + 5 more
π¦ HTTP HEAD Convenience Function
- A convenience function was added for HTTP HEAD requests.
- ```go
- huma.Head(api, "/path", handler)
- ```
π¦ Stop HTML-Escaping JSON
- Before: `expected number \u003e= 10`
- After: `expected number >= 10`
π¦ Groups + Convenience Function Improvements
- ```go
- huma.Get(api, "/v1/users/", handler)
- v1 := huma.NewGroup(api, "/v1")
- users := huma.NewGroup(v1, "/users")
- huma.Get(users, "/", handler)
- fmt.Println(api.OpenAPI().Paths["/v1/users/"].Summary)
- // Output: Get v1 users
- ```
π What's Changed
- feat: adding the head method to the list of convenience wrappers by @hiddenmarten in https://github.com/danielgtaylor/huma/pull/760
- docs: update sponsors by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/764
- fix: do not HTML escape JSON output by default by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/765
- docs: fix model validator docs by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/766
- fix: better integer validation checks by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/768
- feat: better group+convenience function interop by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/770
β¨ New Contributors
- @hiddenmarten made their first contribution in https://github.com/danielgtaylor/huma/pull/760
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.31.0...v2.32.0
π¦ Go 1.24 `omitzero` Support!
- 1. Start with all fields required.
- 2. If a field has `omitempty`, it is optional.
- 3. If a field has `omitzero`, it is optional.
- 4. If a field has `required:"false"`, it is optional.
- 5. If a field has `required:"true"`, it is required.
- See https://huma.rocks/features/request-validation/#optional-required for more info.
π What's Changed
- Add 'omitzero' support to mark optional fields by @JasirZaeem in https://github.com/danielgtaylor/huma/pull/742
- docs: fix typo in groups by @shadow3x3x3 in https://github.com/danielgtaylor/huma/pull/746
β¨ New Contributors
- @JasirZaeem made their first contribution in https://github.com/danielgtaylor/huma/pull/742
- @shadow3x3x3 made their first contribution in https://github.com/danielgtaylor/huma/pull/746
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.30.0...v2.31.0
π¦ Sponsors
- A big thank you to our new sponsor:
- [@nielskrijger](https://github.com/nielskrijger)
π¦ Groups
- ```go
- grp := huma.NewGroup(api, "/v1")
- grp.UseMiddleware(authMiddleware)
- // Register a `GET /v1/users` route that requires auth.
- huma.Get(grp, "/users", func(ctx context.Context, input *struct{}) (*UsersResponse, error) {
- // ...
- })
- ```
- + 1 more
π¦ Context Unwrapping
- > [!CAUTION]
- > You must use the same adapter package to create the API and call `Unwrap` or Huma will panic!
- Example usage:
- ```go
- router := http.NewServeMux()
- api := humago.New(router, huma.DefaultConfig("My API", "1.0.0"))
- api.UseMiddleware(func(ctx huma.Context, next func(huma.Context)) {
- r, w := humago.Unwrap(ctx)
- + 6 more
π What's Changed
- fix docs pointer by @iliadmitriev in https://github.com/danielgtaylor/huma/pull/735
- feat: support context unwrapping by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/736
- feat: groups by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/728
- chore(deps): bump golang.org/x/net from 0.30.0 to 0.33.0 in /examples by @dependabot in https://github.com/danielgtaylor/huma/pull/738
β¨ New Contributors
- @iliadmitriev made their first contribution in https://github.com/danielgtaylor/huma/pull/735
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.29.0...v2.30.0
π¦ Support More Multipart Form Values
- This enabled the use of fields with arbitrary types in the form which will get parsed & validated for you:
- ```go
- huma.Register(api, huma.Operation{
- OperationID: "upload-and-decode-files"
- Method: http.MethodPost,
- Path: "/upload",
- }, func(ctx context.Context, input *struct {
- RawBody huma.MultipartFormFiles[struct {
- + 11 more
π¦ Better Auto-patch Support with Sub-routers
- The auto-patch functionality now tries to find a common path prefix so it's possible to do stuff like this and have the generated `PATCH` operation function correctly:
- ```go
- func main() {
- router := chi.NewRouter()
- router.Route("/api", apiMux())
- err = http.ListenAndServe(fmt.Sprintf(":%d", 8080), router)
- }
- // apiMux returns a function that initializes the API routes
- + 19 more
π¦ Custom Param Type Enhancements
- Two new interfaces enable some additional advanced customization enhancements when creating operation input parameters:
- ```go
- type ParamWrapper interface {
- Receiver() reflect.Value
- }
- type ParamReactor interface {
- OnParamSet(isSet bool, parsed any)
- }
- + 22 more
π Fix Panic from External Schema
- It's possible to use the default schema transformers now with custom external schemas without causing a panic. For example:
- ```go
- Responses: map[string]*huma.Response{
- "200": {
- Content: map[string]*huma.MediaType{
- "application/json": {
- Schema: &huma.Schema{
- Ref: "https://json-schema.org/draft/2020-12/schema",
- + 7 more
π¦ Deep Object Support for Params
- Params now support the OpenAPI `deepObject` style, enabling e.g. query params to send structured input in that style.
- ```go
- // GreetingOutput represents the greeting operation response.
- type GreetingOutput struct {
- Body struct {
- Person Person `json:"person"`
- Map map[string]string `json:"map"`
- }
- + 31 more
π Other fixes
- Prevent double validation errors
- Stop Huma from overwriting a custom request body schema when a `Body` field is present.
π What's Changed
- Update middleware.md by @NeroBlackstone in https://github.com/danielgtaylor/huma/pull/710
- Update middleware.md by @NeroBlackstone in https://github.com/danielgtaylor/huma/pull/712
- feat: allow arbitrary fields in MultipartFormFiles by @b-kamphorst in https://github.com/danielgtaylor/huma/pull/706
- fix: double validation errors by @skwair in https://github.com/danielgtaylor/huma/pull/718
- fix: implement findRelativeRessourcePath function to fix PatchResourc⦠by @froz42 in https://github.com/danielgtaylor/huma/pull/714
- feat: custom query parameter types by @lsdch in https://github.com/danielgtaylor/huma/pull/722
- fix: allow providing a custom request schema by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/727
- fix: do not panic when encountering external schemas by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/729
- + 4 more
β¨ New Contributors
- @NeroBlackstone made their first contribution in https://github.com/danielgtaylor/huma/pull/710
- @skwair made their first contribution in https://github.com/danielgtaylor/huma/pull/718
- @froz42 made their first contribution in https://github.com/danielgtaylor/huma/pull/714
- @shakhzodkudratov made their first contribution in https://github.com/danielgtaylor/huma/pull/731
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.28.0...v2.29.0
π Upgraded Documentation
- Stoplight Elements has been upgraded to the latest version.
π¦ Others
- Fixed two important memory access issues (body race & Fiber context).
- Additional docs & examples added β€οΈ
- Major refactor of some of the codebase to make future changes easier.
π What's Changed
- chore(deps): bump golang.org/x/crypto from 0.28.0 to 0.31.0 by @dependabot in https://github.com/danielgtaylor/huma/pull/676
- fix: useless assertion in TestFeatures/response-image by @alexandear in https://github.com/danielgtaylor/huma/pull/677
- fix: potential body error race by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/687
- feat: upgrade to Stoplight Elements latest by @fourcels in https://github.com/danielgtaylor/huma/pull/689
- fix: adapters/humafiber - prevent to use *fiber.Ctx and *fasthttp.RequestCtx outside handler, fixes #686 by @excavador in https://github.com/danielgtaylor/huma/pull/693
- Fix examples by @alexandermyasnikov in https://github.com/danielgtaylor/huma/pull/696
- docs: describe MultipartFormFiles by @b-kamphorst in https://github.com/danielgtaylor/huma/pull/704
- refactor: split up huma.Register by @b-kamphorst in https://github.com/danielgtaylor/huma/pull/705
β¨ New Contributors
- @alexandermyasnikov made their first contribution in https://github.com/danielgtaylor/huma/pull/696
- @b-kamphorst made their first contribution in https://github.com/danielgtaylor/huma/pull/704
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.27.0...v2.28.0
π¦ Sponsors
- A big thank you to our new sponsors:
- [vinogradovkonst](https://github.com/vinogradovkonst)
- [miyamo2](https://github.com/miyamo2)
- Consider [sponsoring](https://github.com/sponsors/danielgtaylor) the project!
π¦ Better Handling of Embedded Header Fields
- ```go
- // PaginationOutput contains reusable response headers
- // for implementing pagination
- type PaginationOutput struct {
- Link string `header:"Link" doc:"HTTP links for e.g. pagination"`
- Cursor string `header:"Cursor" doc:"Identifier that can be used to paginate. If the value is empty then there are no more pages to iterate over."`
- }
- // list_slates.go
- + 5 more
ποΈ Remove Chi From Tests
- The code has been refactored to remove reliance on Chi for the tests, simplifying the project overall and relying more on the standard library.
π Fix Operation Callbacks
- ```yaml
- paths:
- /create:
- post:
- callbacks:
- myEvent:
- "{$request.body#/callbackUrl}":
- post:
- + 3 more
π¦ Better Support for Embedded RawBody Field
- It's now possible to embed the `RawBody` field and have things work. For example:
- ```go
- type RequestHeader struct {
- Test string `header:"Test"`
- }
- type EmbedGreeting struct {
- RawBody multipart.Form
- }
- + 5 more
π¦ `ContentTypeFilter` Now Updates OpenAPI
- ```go
- type Response struct {
- Message string `json:"message" doc:"The message."`
- }
- func (r *Response) ContentType(t string) string {
- return "application/ld+json"
- }
- type Output struct {
- + 3 more
π Other Fixes
- Various doc fixes / improvements
- New linters enabled for better code quality
π What's Changed
- fix: write errors/warnings to stderr rather than stdout by @sm3142 in https://github.com/danielgtaylor/huma/pull/651
- Exclude embedded fields in response header docs by @lucaspopp-wbd in https://github.com/danielgtaylor/huma/pull/656
- Propagate fiberCtx.UserContext() to huma.Context - Context() by @excavador in https://github.com/danielgtaylor/huma/pull/659
- Chi is a dep even for pure go implementations, refactor its usage in the main package to pure go. by @fwilkerson in https://github.com/danielgtaylor/huma/pull/661
- fix: operation callbacks shape by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/665
- feat: support embedded raw body fields by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/666
- fix: body with ContentTypeFilter should update OpenAPI by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/667
- fix oauth2-jwt.md mermaid rendering issue by @ssoroka-tc in https://github.com/danielgtaylor/huma/pull/668
- + 3 more
β¨ New Contributors
- @sm3142 made their first contribution in https://github.com/danielgtaylor/huma/pull/651
- @excavador made their first contribution in https://github.com/danielgtaylor/huma/pull/659
- @fwilkerson made their first contribution in https://github.com/danielgtaylor/huma/pull/661
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.26.0...v2.27.0
π¦ Better Marking of Visited Types
- ```go
- type Address struct {
- Line1 string `json:"line1" required:"true" minLength:"1" maxLength:"50"`
- Line2 string `json:"line2,omitempty" required:"false" minLength:"0" maxLength:"50" default:""`
- City string `json:"city" required:"true" minLength:"1" maxLength:"64"`
- State string `json:"state" required:"true" minLength:"1" maxLength:"32"`
- Zip string `json:"zip" required:"true" minLength:"1" maxLength:"16"`
- CountryCode string `json:"countryCode" required:"false" minLength:"1" maxLength:"2" default:"US"`
- + 11 more
π¦ Others
- Fixed doc bug
- Minor fix when printing response bodies in tests if JSON indenting fails
- Refactored code for sending responses to be more consistent & re-used between the handlers and `WriteErr` and ensure `NewErrorWithContext` is used everywhere. This should be a no-op for library users.
π What's Changed
- fix: doc comments for TestAPI functions by @alexandear in https://github.com/danielgtaylor/huma/pull/644
- fix: marking visited types in findInType by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/641
- fix: make content negotiation more resilient to bad input by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/645
- fix: dump body directly if json indent fails by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/643
- refactor: use WriteErr function for handling error returned by handler by @notjustmoney in https://github.com/danielgtaylor/huma/pull/640
- fix: do not panic on client disconnect by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/650
β¨ New Contributors
- @notjustmoney made their first contribution in https://github.com/danielgtaylor/huma/pull/640
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.25.0...v2.26.0
π¦ Case-insensitive JSON
- ```go
- 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
- + 3 more
π¦ 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:
- ```go
- type MyInput struct {
- Body struct {
- Enabled *bool `json:"enabled,omitempty" default:"true"`
- }
- }
- ```
- + 7 more
π What's Changed
- Update request-resolvers.md by @alexanderilyin in https://github.com/danielgtaylor/huma/pull/619
- docs: fix YAML command example by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/624
- feat: case-insensitive field matching for JSON/CBOR by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/629
- feat: allow scalar pointers with defaults by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/633
- Update build-sdk.sh by @MaximeWeyl in https://github.com/danielgtaylor/huma/pull/637
β¨ New Contributors
- @MaximeWeyl made their first contribution in https://github.com/danielgtaylor/huma/pull/637
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.24.0...v2.25.0
π¦ Better Support of String Subtype Slice Params
- It's now possible to use types based on `string` like you commonly see for enumerations as slice inputs to Huma operations.
- ```go
- type MyEnum string
- const (
- Value1 MyEnum = "value1"
- Value2 MyEnum = "value2"
- // ...
- )
- + 6 more
π¦ Better Support of non-Object Refs
- ```go
- type InstitutionKind string
- const (
- Lab InstitutionKind = "Lab"
- FoundingAgency InstitutionKind = "FundingAgency"
- SequencingPlatform InstitutionKind = "SequencingPlatform"
- Other InstitutionKind = "Other"
- )
- + 19 more
π Fix Empty Security Marshaling
- The empty security object has semantic meaning in OpenAPI 3.x which enables you to override a global security setting to make one or more operations public. It's now possible to do so:
- ```go
- huma.Register(api, huma.Operation{
- OperationID: "GetUser",
- Method: http.MethodGet,
- Path: "/user/{id}",
- Security: []map[string][]string{}, // This will not require security!
- }, func(ctx context.Context, input *GetUserInput) (*GetUserOutput, error) {
- + 5 more
π¦ Expanded Adapter Interface
- The `huma.Adapter` interface now has methods for getting the HTTP version and TLS info of the incoming request, which enables better tracing middleware using e.g. OpenTelemetry.
π¦ Read-Only & Write-Only Behavior Clarification
- The read and write-only behavior of Huma validation has been clarified in the docs. See https://huma.rocks/features/request-validation/#read-and-write-only to ensure it works as you expect.
π What's Changed
- Fix typo in request-inputs.md by @j0urneyK in https://github.com/danielgtaylor/huma/pull/591
- refactor: use type switch instead of if-else by @alexandear in https://github.com/danielgtaylor/huma/pull/595
- chore: enable dupword; fix appeared lint issues by @alexandear in https://github.com/danielgtaylor/huma/pull/598
- docs: fix typos in docs, comments, and tests by @alexandear in https://github.com/danielgtaylor/huma/pull/596
- fix: panic - allow for parameters to be subtype of string by @hlavavit in https://github.com/danielgtaylor/huma/pull/592
- fix: check actual type in schema ref when enforcing non-nullable object schemas by @lsdch in https://github.com/danielgtaylor/huma/pull/599
- fix: dependency upgrades, fixes #569 by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/601
- docs: add new testimonial to README by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/602
- + 8 more
β¨ New Contributors
- @j0urneyK made their first contribution in https://github.com/danielgtaylor/huma/pull/591
- @alexandear made their first contribution in https://github.com/danielgtaylor/huma/pull/595
- @hlavavit made their first contribution in https://github.com/danielgtaylor/huma/pull/592
- @fntz made their first contribution in https://github.com/danielgtaylor/huma/pull/610
- @alexanderilyin made their first contribution in https://github.com/danielgtaylor/huma/pull/615
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.23.0...v2.24.0
π¦ Pointers for Non-Param Fields
- ```go
- type EndpointInput struct {
- Token string `header:"Authorization"`
- User *User
- }
- func (i *EndpointInput) Resolve(ctx huma.Context) []error {
- user, token_valid := ValidateToken(i.Token) // user is nil if token is missing or invalid
- i.User = user
- + 3 more
π¦ Hidden Field Validation
- Hidden fields are now validated properly if they are present in the input. For example:
- ```go
- huma.Put(api, "/demo", func(ctx context.Context, input *struct{
- Body struct {
- Field1 string `json:"field1"
- Field2 int `json:"field2" hidden:"true" minimum:"10"`
- }
- }) (*MyResponse, error) {
- + 5 more
β¨ NewError with a Context
- It's now possible to replace `huma.NewErrorWithContext` so your error generation function has access to the underlying request context.
π NewWithPrefix & Servers
- When using `humago.NewWithPrefix` and not providing any servers, a single server entry is now generated for you with the given prefix.
π¦ Support `url.URL` Parameters
- You can now use a URL as an input path/query/header parameter and it will be parsed/validated for you.
π¦ Request Body Generation Improvements
- ```go
- func (tr TEERouter) RegisterRoutes(api huma.API) {
- operation := huma.Operation{
- Method: http.MethodPost,
- Path: "/tee",
- Summary: "TEE",
- Description: "TEE description",
- RequestBody: &huma.RequestBody{
- + 6 more
π What's Changed
- Allow using pointers for non param fields in input structs by @lsdch in https://github.com/danielgtaylor/huma/pull/565
- fix: validate hidden fields by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/573
- fix: prevent overwriting schema validations by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/575
- fix: support non-addressable resolver values by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/580
- fix: use status code returned from NewError when writing errors by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/581
- add NewErrorWithContext by @nunoo in https://github.com/danielgtaylor/huma/pull/582
- Add default Server object when calling humago.NewWithPrefix by @yursan9 in https://github.com/danielgtaylor/huma/pull/579
- fix: unsupported param type url.URL by @ddl-ebrown in https://github.com/danielgtaylor/huma/pull/584
- + 1 more
β¨ New Contributors
- @yursan9 made their first contribution in https://github.com/danielgtaylor/huma/pull/579
- @ddl-ebrown made their first contribution in https://github.com/danielgtaylor/huma/pull/584
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.22.1...v2.23.0
π What's Changed
- fix: reset recovery middleware buffer by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/572
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v1.14.2...v1.14.3
π What's Changed
- fix: order of operations when resetting buffer by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/553
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.22.0...v2.22.1
π¦ Sponsors
- A big thank you to our new sponsor:
- @steamsets
π¦ Minimum Go Version: 1.21
- > Each major Go release is supported until there are two newer major releases. For example, Go 1.5 was supported until the Go 1.7 release, and Go 1.6 was supported until the Go 1.8 release.
- https://go.dev/doc/devel/release
π Fixes Raw Body Race Condition
- > [!WARNING]
- > If you use the `RawBody` feature, you should upgrade immediately. This bug results in incorrect/corrupted data.
π¦ Better `encoding.TextUnmarshaler` Support
- ```go
- type MyDate time.Time
- func (d *MyDate) UnmarshalText(data []byte) error {
- t, err := time.Parse(time.RFC3339, string(data))
- if err != nil {
- return err
- }
- *d = MyDate(t)
- + 7 more
π¦ Precompute Schema Validation
- If you modify a schema after registration, you must still call `PrecomputeMessages()` manually to update the messages.
π What's Changed
- fix: race by deferring the return of buf to sync.Pool when using RawBody by @nunoo in https://github.com/danielgtaylor/huma/pull/542
- fix: automatically precompute schema validation messages by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/545
- fix: if err & response are nil, return default status by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/546
- feat: Update minimum Go version to 1.21 by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/547
- chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.1 to 2.52.5 by @dependabot in https://github.com/danielgtaylor/huma/pull/549
- feat: treat encoding.TextUnmarshaler as string in schema by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/550
β¨ New Contributors
- @nunoo made their first contribution in https://github.com/danielgtaylor/huma/pull/542
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.21.0...v2.22.0
π¦ Better Support for Default/Example in Custom Schemas
- Fixes an issue where custom schemas could have values overwritten by the default instead of using the given value. For example:
- ```go
- type GreetingType int
- func (*GreetingType) Schema(r huma.Registry) *huma.Schema {
- schema := &huma.Schema{
- Type: huma.TypeInteger,
- Default: 10,
- Examples: []any{1},
- + 4 more
π¦ Better Errors When Using Discriminators
- ```go
- type Cat struct {
- Name string `json:"name" minLength:"2" maxLength:"10"`
- Kind string `json:"kind" enum:"cat"`
- }
- type Dog struct {
- Color string `json:"color" enum:"black,white,brown"`
- Kind string `json:"kind" enum:"dog"`
- + 32 more
π What's Changed
- fix(schema): default value not work by @fourcels in https://github.com/danielgtaylor/huma/pull/531
- fix(typo): accmplished -> accomplished by @superstas in https://github.com/danielgtaylor/huma/pull/534
- fix(schema): schema example not work in Parameter by @fourcels in https://github.com/danielgtaylor/huma/pull/532
- #533: Add Validation for Discriminator with OneOf and Mapping. by @superstas in https://github.com/danielgtaylor/huma/pull/536
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.20.0...v2.21.0
π¦ Sponsors
- Thank you to [Zuplo](https://zuplo.link/huma-web) for sponsoring the project.
π¦ Customizable Validation Errors
- Validation errors are now completely customizable as globals in the library.
- ```go
- // Set a custom message for minimum validation failure.
- huma.MsgExpectedMinimumNumber = "expected number bigger than or equal to %v"
- ```
- ```go
- var ErrorFormatter func(format string, a ...any) string = fmt.Sprintf
- ```
π What's Changed
- fix(schema): proper minLength, maxLength in generated schemas. by @superstas in https://github.com/danielgtaylor/huma/pull/513
- fix(schema): proper minimum, maximum in generated schemas. by @superstas in https://github.com/danielgtaylor/huma/pull/515
- fix(schema): add dereferencing for SchemaFromType by @superstas in https://github.com/danielgtaylor/huma/pull/518
- feat: add zuplo sponsorship by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/501
- docs: fix formatting in sponsors by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/523
- feat: make validation error messages customizable by @smacker in https://github.com/danielgtaylor/huma/pull/520
- fix: nullable schemas for arrays/slices by @lsdch in https://github.com/danielgtaylor/huma/pull/527
β¨ New Contributors
- @superstas made their first contribution in https://github.com/danielgtaylor/huma/pull/513
- @smacker made their first contribution in https://github.com/danielgtaylor/huma/pull/520
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.19.0...v2.20.0
π¦ Sponsors
- A big thank you to our new sponsor:
- @chenjr0719
π¦ Multipart Form File Metadata
- It's now possible to get filename & size metadata information from multipart form files.
- ```go
- 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()
- + 4 more
π§ͺ Easier Custom Context When Testing
- ```go
- _, 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.
- ```go
- huma.Get(api, "/example", func(ctx context.Context, input *struct{
- Value []string `query:"value,explode"`
- }) (*struct{}, error) {
- fmt.Println(input.Value)
- return nil, nil
- })
- + 2 more
π¦ 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 https://github.com/danielgtaylor/huma/pull/466
- Extend TestAPI interface to allow for custom context.Context by @coury-clark in https://github.com/danielgtaylor/huma/pull/469
- Update README_CN.md by @Ivlyth in https://github.com/danielgtaylor/huma/pull/477
- remove response body from panic message by @austincollinpena in https://github.com/danielgtaylor/huma/pull/479
- fix(schema): proper array minItems, maxItems and doc reporting in generated schemas by @Grumpfy in https://github.com/danielgtaylor/huma/pull/485
- fix: remove slices dependency to better support Go 1.20 by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/497
- Implement exploded query parameters by @csmarchbanks in https://github.com/danielgtaylor/huma/pull/498
- Improvement Autopatch (adding a body) by @ScriptType in https://github.com/danielgtaylor/huma/pull/496
- + 1 more
β¨ New Contributors
- @coury-clark made their first contribution in https://github.com/danielgtaylor/huma/pull/469
- @Ivlyth made their first contribution in https://github.com/danielgtaylor/huma/pull/477
- @Grumpfy made their first contribution in https://github.com/danielgtaylor/huma/pull/485
- @csmarchbanks made their first contribution in https://github.com/danielgtaylor/huma/pull/498
- @ScriptType made their first contribution in https://github.com/danielgtaylor/huma/pull/496
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.18.0...v2.19.0
π¦ Better Multipart Files Uploads
- ```go
- type FileData struct {
- // This is an example, any number of `multipart.File` fields can be defined.
- // Nested structs are not supported.
- SomeFile multipart.File `form-data:"some_file" content-type:"image/png" required:"true"`
- SeveralFiles []multipart.File `form-data:"several_files" content-type:"image/png,image/jpeg" required:"true"`
- }
- type FileHandlerInput struct {
- + 14 more
π¦ Schema Transformers
- ```go
- type SchemaTransformer interface {
- TransformSchema(r Registry, s *Schema) *Schema
- }
- ```
- Simple example:
- ```go
- type MyInput struct {
- + 7 more
π What's Changed
- Fix typo in SSE doc by @op-tmplt in https://github.com/danielgtaylor/huma/pull/448
- Feature: handling files from `multipart/form-data` request by @lsdch in https://github.com/danielgtaylor/huma/pull/415
- feat: allow modifying generated schema by implementing SchemaTransformer interface by @lsdch in https://github.com/danielgtaylor/huma/pull/456
- fix: type schema description not work by @fourcels in https://github.com/danielgtaylor/huma/pull/462
β¨ New Contributors
- @op-tmplt made their first contribution in https://github.com/danielgtaylor/huma/pull/448
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.17.0...v2.18.0
π¦ Convenience Method Operation Modifiers
- You can now add modifier functions when registering operations using convenience methods like `huma.Get`:
- ```go
- func OperationTags(tags ...string) func(o *Operation) {
- return func(o *Operation) {
- o.Tags = tags
- }
- }
- huma.Get(api, "/demo", myHandler, OperationTags("one", "two"))
- + 1 more
β¨ Request Remote Address Access
- It's now possible to access the requests's `RemoteAddr` field through `huma.Context` for use in middleware and/or resolvers, which works with all routers:
- ```go
- func MyMiddleware(ctx huma.Context, next func(huma.Context)) {
- fmt.Println("Request address", ctx.RemoteAddr())
- next(ctx)
- }
- ```
π Fix Unmarshaling of Embedded Body
- Unmarshaling of embedded structs with a body field now works as expected:
- ```go
- type BodyContainer struct {
- Body struct {
- Name string `json:"name"`
- }
- }
- huma.Register(api, huma.Operation{
- + 9 more
π What's Changed
- feat: convenience methods with operationHandlers by @fourcels in https://github.com/danielgtaylor/huma/pull/434
- fix: race condition in CLI tests by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/436
- docs: add new sponsor and quote by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/437
- fix: unmarshaling of request body when using struct embedding by @lsdch in https://github.com/danielgtaylor/huma/pull/440
- feat: add request remote address to context by @danielgtaylor in https://github.com/danielgtaylor/huma/pull/447
β¨ New Contributors
- @fourcels made their first contribution in https://github.com/danielgtaylor/huma/pull/434
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.16.0...v2.17.0
π¦ Better Panics
- Some panic messages have been improved to be more helpful for users, for example letting them know that the response type must be a struct rather than some confusing reflection panic.
π What's Changed
- feat!: drop chi v4 adapter by @costela in https://github.com/danielgtaylor/huma/pull/427
- panic with more descriptive messages by @ssoroka in https://github.com/danielgtaylor/huma/pull/431
- Full Changelog: https://github.com/danielgtaylor/huma/compare/v2.15.0...v2.16.0
