Releases: muonsoft/validation
Releases · muonsoft/validation
v0.19.0
What's Changed
Added
- Slice validation:
Slice,SliceProperty,Each, andEachPropertyfor 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
EachandThis.
Changed
- Validator initialization: Global validator replaced with atomic pointer for thread-safe usage. Use new validator setup methods in tests.
- CheckNoViolations: Now accepts variadic
errorsfor 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
CheckNoViolationsor validator setup need to be updated to the new signatures and helpers.
Full Changelog: v0.18.0...v0.19.0
v0.18.0
What's Changed
New
UnwrapViolations(err)— Single function to unwrap both a singleViolationandViolationListfrom an error. Use this instead ofUnwrapViolationandUnwrapViolationList.ViolationList.All()— Iterator over violations forrangeloops:for i, v := range violations.All() { ... }PropertyPath.All()— Iterator over property path elements forrangeloops
Deprecated
UnwrapViolationandUnwrapViolationList— UseUnwrapViolationsinstead.
Requirements
- Go 1.24 or later
Full Changelog: v0.17.0...v0.18.0
v0.17.0
What's Changed
- docs updated by @strider2038 in #77
- ULID validation by @strider2038 in #78
- UUID validation by @strider2038 in #79
- divisible by validation by @strider2038 in #80
- feature: at property by @strider2038 in #81
- bump golang x text dependency by @strider2038 in #82
Full Changelog: v0.16.0...v0.17.0
v0.16.0
- BC break stored constraints removed
- BC break ip testing function signature updated to return error instead of bool
Instance()function invalidatorpackage
Full Changelog: v0.15.0...v0.16.0
v0.15.0
validation.ValidatableFuncadded as a functional adapter forvalidation.Validatableinterfacevalidation.BuiltinViolationFactoryis now exported and can be reused- few code examples added for some complex cases
v0.14.0
- Feature:
it.DateTimeConstraintto 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 ofPropertyPathElement - method
Len()returns length of the property path
- method
- Feature: additional checks for
it.URLConstraint:WithHoststo check list of allowed hostsWithHostMatchesto check host by regexp patternWithRestrictionto check by closure
- breaking changes in packages
isandvalidate:validate.URL(value string, schemas ...string) errorsignature replaced byvalidate.URL(value string, restrictions ...URLRestriction) erroris.URL(value string, schemas ...string) errorsignature replaced byis.URL(value string, restrictions ...URLRestriction) error
v0.13.2
fix: revert behaviour for it.ChoiceConstraint (method WithAllowedBlank replaced by WithoutBlank)
v0.13.1
- violations formatting updated
- more detailed assertion errors for violation assertions
v0.13.0
- big refactoring with breaking changes
- validation codes replaced by static errors
validation.Erroradded with constructorvalidation.NewError()Violation.Code() stringreplaced byViolation.Unwrap() errormethod- package
coderemoved - all
Violationimplementations can now be tested by standarderrors.Is()function for containing static errors
- most of constraint method names now are suffixed with
With it.IsEqualToString,it.IsNotEqualToString,it.IsEqualToNumber,it.IsNotEqualToNumberremovedvalidation.ViolationList.Each()renamed tovalidation.ViolationList.ForEach()validation.ViolationList.Has()replaced byvalidation.ViolationList.Is()- signatures for all constraints updated from
Validate<Type>(value, scope)toValidate<Type>(ctx, validator, value) validation.Scoperemoved (all exported methods moved tovalidation.Validator)validation.NewTypedArgument()renamed tovalidation.This()validation.CustomStringConstraintrenamed tovalidation.StringFuncConstraintvalidation.NewCustomStringConstraint()renamed tovalidation.OfStringBy()validation.Languageargument removedvalidation.Optionand all implementations removed- argument
WithwithOptionmethod replaced byAtmethod with property path validation.PropertyNameElementrenamed tovalidation.PropertyNamevalidation.ArrayIndexElementrenamed tovalidation.ArrayIndexit.NotBlankConstraint.AllowNil()renamed toit.NotBlankConstraint.WithAllowedNil()it.ChoiceConstraintblank value behaviour updated (additional methodWithAllowedBlank()added)- all previous deprecations removed
See all updates in pull request #74
v0.12.0
- Feature: Generic
Constraintinterface andNewTypedArgumentconstructor. - Feature:
AllArgumentfor composing a complex validation. - Feature:
AsyncArgumentfor asynchronous validation. - Fixed: All error methods now have pointer receivers.