Files
valid/CHANGELOG.md
Rene Nochebuena ab11fd2ace feat(valid)!: promote to v1.0.0 — JSON tag name resolution, bump xerrors to v1.0.0
Resolve JSON tag name resolution roadmap item: field names in error context
now use the json struct tag when available, falling back to the Go field name.
Commits MessageProvider interface as stable. Bumps xerrors dependency from
v0.9.0 to v1.0.0. API committed as stable.
2026-05-11 18:18:05 -06:00

2.6 KiB

Changelog

All notable changes to this module will be documented in this file.

The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.

1.0.0 — 2026-05-12

Added

  • JSON tag name resolution — field names in error context now use the json struct tag when available (e.g. "email_address" instead of "EmailAddress"), falling back to the Go field name when no json tag is defined or the tag is "-".

Changed

  • xerrors dependency bumped from v0.9.0 to v1.0.0.

Unchanged

All existing API (Validator, New, WithMessageProvider, MessageProvider, DefaultMessages, SpanishMessages) is API-compatible with v0.9.0.

0.9.0 - 2026-03-18

Added

  • Validator interface with a single Struct(v any) error method for struct tag validation.
  • New(opts ...Option) Validator constructor; returns an English-language validator by default.
  • Option functional-option type for configuring a Validator at construction time.
  • WithMessageProvider(mp MessageProvider) Option option to replace the built-in message provider.
  • MessageProvider interface with Message(field, tag, param string) string; implement to supply custom or localised messages.
  • DefaultMessages (MessageProvider): built-in English messages for required, email, min, max, and a generic fallback.
  • SpanishMessages (MessageProvider): opt-in Spanish translations for the same tag set.
  • Error behaviour: a failing struct field returns *xerrors.Err with code ErrInvalidInput; structured context keys "field" and "tag" are attached via WithContext. The raw playground.ValidationErrors is chained via WithError for callers that need all failures.
  • Error behaviour: passing a non-struct value returns *xerrors.Err with code ErrInternal (wrapping playground.InvalidValidationError).
  • Only the first failing field is surfaced per Struct call; the full error slice is preserved in the error chain.

Design Notes

  • go-playground/validator/v10 is used as the backend but is entirely hidden behind the Validator interface; no playground types appear in the public API.
  • MessageProvider decouples human-readable text from validation logic, enabling i18n without any changes to the core package.
  • A single *playground.Validate instance is created per Validator (not per call) to amortise the cost of reflection-based type caching.