Skip to content

Releases: muonsoft/validation

v0.19.0

09 Feb 16:55

Choose a tag to compare

What's Changed

Added

  • Slice validation: Slice, SliceProperty, Each, and EachProperty for validating slices with per-element constraints.
  • HasUniqueValuesBy: Constraint to ensure slice elements are unique by a key function.
  • Validate method on constraints: Constraints can now be used directly with Each and This.

Changed

  • Validator initialization: Global validator replaced with atomic pointer for thread-safe usage. Use new validator setup methods in tests.
  • CheckNoViolations: Now accepts variadic errors for improved error handling and termination conditions.
  • Documentation: README restructured with installation, custom constraints, and property paths; expanded custom constraints guide with interface details and examples.
  • Skill docs: SKILLS.md removed; new reference and skill documentation for adding validation constraints.

Fixed

  • Correct handling of single violations returned from validatable objects in validateIt.

Breaking Changes

  • Tests using CheckNoViolations or validator setup need to be updated to the new signatures and helpers.

Full Changelog: v0.18.0...v0.19.0

v0.18.0

04 Feb 17:12
076e0ab

Choose a tag to compare

What's Changed

New

  • UnwrapViolations(err) — Single function to unwrap both a single Violation and ViolationList from an error. Use this instead of UnwrapViolation and UnwrapViolationList.
  • ViolationList.All() — Iterator over violations for range loops: for i, v := range violations.All() { ... }
  • PropertyPath.All() — Iterator over property path elements for range loops

Deprecated

  • UnwrapViolation and UnwrapViolationList — Use UnwrapViolations instead.

Requirements

  • Go 1.24 or later

Full Changelog: v0.17.0...v0.18.0

v0.17.0

11 Mar 09:06
59a89fe

Choose a tag to compare

What's Changed

Full Changelog: v0.16.0...v0.17.0

v0.16.0

26 Oct 18:24

Choose a tag to compare

  • BC break stored constraints removed
  • BC break ip testing function signature updated to return error instead of bool
  • Instance() function in validator package

Full Changelog: v0.15.0...v0.16.0

v0.15.0

31 Jul 18:55

Choose a tag to compare

  • validation.ValidatableFunc added as a functional adapter for validation.Validatable interface
  • validation.BuiltinViolationFactory is now exported and can be reused
  • few code examples added for some complex cases

v0.14.0

17 Jul 19:18
05cfc84

Choose a tag to compare

  • Feature: it.DateTimeConstraint to validate date time values
  • Feature: marshal complex property path values into string
  • Feature: property path unmarshaling from string
  • Feature: new methods for validation.PropertyPath:
    • method Elements() returns property path as slice of PropertyPathElement
    • method Len() returns length of the property path
  • Feature: additional checks for it.URLConstraint:
    • WithHosts to check list of allowed hosts
    • WithHostMatches to check host by regexp pattern
    • WithRestriction to check by closure
  • breaking changes in packages is and validate:
    • validate.URL(value string, schemas ...string) error signature replaced by validate.URL(value string, restrictions ...URLRestriction) error
    • is.URL(value string, schemas ...string) error signature replaced by is.URL(value string, restrictions ...URLRestriction) error

v0.13.2

16 Jul 05:17

Choose a tag to compare

fix: revert behaviour for it.ChoiceConstraint (method WithAllowedBlank replaced by WithoutBlank)

v0.13.1

14 Jul 19:59
419bb42

Choose a tag to compare

  • violations formatting updated
  • more detailed assertion errors for violation assertions

v0.13.0

10 Jul 17:35
03ceef9

Choose a tag to compare

  • big refactoring with breaking changes
  • validation codes replaced by static errors
    • validation.Error added with constructor validation.NewError()
    • Violation.Code() string replaced by Violation.Unwrap() error method
    • package code removed
    • all Violation implementations can now be tested by standard errors.Is() function for containing static errors
  • most of constraint method names now are suffixed with With
  • it.IsEqualToString, it.IsNotEqualToString, it.IsEqualToNumber, it.IsNotEqualToNumber removed
  • validation.ViolationList.Each() renamed to validation.ViolationList.ForEach()
  • validation.ViolationList.Has() replaced by validation.ViolationList.Is()
  • signatures for all constraints updated from Validate<Type>(value, scope) to Validate<Type>(ctx, validator, value)
  • validation.Scope removed (all exported methods moved to validation.Validator)
  • validation.NewTypedArgument() renamed to validation.This()
  • validation.CustomStringConstraint renamed to validation.StringFuncConstraint
  • validation.NewCustomStringConstraint() renamed to validation.OfStringBy()
  • validation.Language argument removed
  • validation.Option and all implementations removed
  • argument With with Option method replaced by At method with property path
  • validation.PropertyNameElement renamed to validation.PropertyName
  • validation.ArrayIndexElement renamed to validation.ArrayIndex
  • it.NotBlankConstraint.AllowNil() renamed to it.NotBlankConstraint.WithAllowedNil()
  • it.ChoiceConstraint blank value behaviour updated (additional method WithAllowedBlank() added)
  • all previous deprecations removed

See all updates in pull request #74

v0.12.0

22 Jun 18:01

Choose a tag to compare

  • Feature: Generic Constraint interface and NewTypedArgument constructor.
  • Feature: AllArgument for composing a complex validation.
  • Feature: AsyncArgument for asynchronous validation.
  • Fixed: All error methods now have pointer receivers.