Files
valid/CHANGELOG.md

49 lines
2.6 KiB
Markdown
Raw Normal View History

# Changelog
All notable changes to this module will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [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.
[1.0.0]: https://code.nochebuena.dev/go/valid/releases/tag/v1.0.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.
[0.9.0]: https://code.nochebuena.dev/go/valid/releases/tag/v0.9.0