Skip to content

Releases: danielgtaylor/huma

v2.8.0

11 Mar 16:34
13acb69
Compare
Choose a tag to compare

Overview

CLI Package

The CLI functionality has been moved into its own package humacli. The existing huma.NewCLI call continues to work but is marked as deprecated and will be removed in a future release. This will be a small breaking change in the future but is necessary to fix a design mistake that impacts dependencies that cannot otherwise be resolved. Migrating is an easy find/replace:

  • huma.NewCLIhumacli.New
  • huma.CLIhumacli.CLI
  • huma.Hookshumacli.Hooks
  • huma.WithOptionshumacli.WithOptions

If you want to ensure your code doesn't include anything from the existing CLI and Cobra functionality, use the humanewclipackage build tag, e.g. go build -tags humanewclipackage. You won't save much space but this can help for package auditing.

Convenience Summary

Convenience functions like huma.Get, huma.Put, etc now generate a human-readable summary of the operation using the path. For example, huma.Get(api, "/things/{id}", ...) would generate a summary of Get things by id.

Easier Context Values

Router-agnostic middleware has gotten a bit easier to write with the new huma.WithValue and huma.WithContext functions to return a wrapped Huma context with its underlying request context.Context replaced. Use it like:

func MyMiddleware(ctx huma.Context, next func(huma.Context)) {
	// Wrap the context to add a value.
	ctx = huma.WithValue(ctx, "some-key", "some-value")

	// Call the next middleware in the chain. This eventually calls the
	// operation handler as well.
	next(ctx)
}

What's Changed

New Contributors

Full Changelog: v2.7.0...v2.8.0

v2.7.0

05 Mar 06:07
v2.7.0
aa2e3a7
Compare
Choose a tag to compare

New Features

Convenience Functions

Convenience functions are available for common HTTP verbs, e.g. huma.Get, huma.Post, huma.Put, etc. These provide less control over the OpenAPI generation, but are significantly less verbose than huma.Register and make it easier to get started, provide quick examples/demos, and more.

huma.Get(api, "/demo", func(ctx context.Context, input *Input) (*Output, error) {
	// ...
})

The OpenAPI operationId field is generated from the path. The behavior can be modified by overriding huma.GenerateOperationID if desired. It's easy to switch to huma.Register at any time if/when you want to provide more information for the OpenAPI generation.

Custom Input Params

You can now use any type that supports encoding.TextUnmarshaler as an input param (path/query/header/cookie). Combined with custom field schemas this is very powerful, and it can use custom request resolvers as well enabling better support for exhaustive error responses to clients. For example, the Google UUID library supports TextUnmarshaler:

import "github.com/google/uuid"

type UUID struct {
	uuid.UUID
}

func (UUID) Schema(r huma.Registry) *huma.Schema {
	return &huma.Schema{Type: huma.TypeString, Format: "uuid"}
}

huma.Get(api, "/demo", func(ctx context.Context, input *struct{
	Example UUID `query:"example"`
}) (*Output, error) {
	// Print out the UUID time portion
	fmt.Println(input.Example.Time())
})

What's Changed

New Contributors

Full Changelog: v2.6.0...v2.7.0

v2.6.0

26 Feb 16:14
v2.6.0
95a3021
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.5.0...v2.6.0

v2.5.0

20 Feb 17:01
v2.5.0
15f15fe
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.4.0...v2.5.0

v2.4.0

04 Feb 17:38
v2.4.0
42461d5
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.3.0...v2.4.0

v2.3.0

25 Jan 18:02
v2.3.0
c212880
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.2.0...v2.3.0

v2.2.0

06 Jan 01:00
v2.2.0
1d337f1
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.1.0...v2.2.0

v2.1.0

13 Dec 17:55
v2.1.0
8f08975
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.0.1...v2.1.0

v2.0.1

10 Dec 17:14
v2.0.1
f875445
Compare
Choose a tag to compare

What's Changed

  • fix(gorilla/mux): properly register operations with the router by @danielgtaylor in #180

Full Changelog: v2.0.0...v2.0.1

v2.0.0

02 Dec 23:54
v2.0.0
f54b62a
Compare
Choose a tag to compare

This is a major new release with a completely rewritten interface using Go generics. Please see https://huma.rocks/ for documentation!

What's Changed

Full Changelog: v2.0.0-rc.1...v2.0.0