Skip to content

v2.12.0

Compare
Choose a tag to compare
@danielgtaylor danielgtaylor released this 08 Apr 15:38
· 199 commits to main since this release
6247e82

Overview

Support json.RawMessage

There is now better support in the validator for json.RawMessage, which turns into an empty schema (allow anything).

type Demo struct {
  Field1 string          `json:"field1"`
  Field2 json.RawMessage `json:"field2"`
}

OpenAPI 3.0.3

It's now easy to get OpenAPI 3.0.3 from a Huma service for tools that aren't completely compatible with OpenAPI 3.1 just yet. See https://huma.rocks/features/openapi-generation/. The new specs are available at /openapi-3.0.json and /openapi-3.0.yaml by default. Programmatic access is available via api.OpenAPI().Downgrade().

Better Support for Optional / Nullable Types

Huma now has better support for optional/nullable schemas. Broadly speaking, omitempty controls whether a field is optional/required and the use of a pointer controls nullability. As described in:

Huma generates type arrays from pointers to simple scalar types (boolean, integer, number, string) like "type": ["string", "null"]. This is especially useful for frontend languages like Javascript/Typescript where there is a distinction between explicit null vs. undefined and an SDK generator might produce a type union like:

// Generated Typescript example
type GreetingOutputBody = {
  message: string | null;
};

In addition to the default automatic behavior for determining optional/nullable, these can be manually overridden by the user via the required:"true|false" and nullable:"true|false" field tags, ensuring you have full control over how the schema is generated.

Important

Types which result in a JSON array or object are not marked as nullable by default, due to the complexity of modeling this in JSON Schema and poor support from SDK generators for Go and some other languages. This may change in a future release. You can mark a struct as nullable manually using a _ field with a nullable:"true" tag as described in the docs linked above.

What's Changed

New Contributors

Full Changelog: v2.11.0...v2.12.0