Releases: GraHms/godantic
feat: allow extra fields
add support for object bypass
Merge pull request #22 from GraHms/feat/support-objects feat: add support for godantic.Object type
Godantic v1.5.0 — Custom Tags, Plugins & Dynamic Fields
🚀 Godantic v1.5.0 — Custom Tags, Plugins & Dynamic Fields
We are proud to announce Godantic v1.5.0, a powerful and extensible validation engine for Go! This release marks a significant leap forward in flexibility, allowing developers to inject custom logic and support dynamic schemas like never before.
✨ Highlights
✅ Custom Validation Tags
You can now register your own validation rules with type-safe generic functions:
godantic.RegisterCustom[string]("starts_with_A", func(val string, path string) *godantic.Error {
if !strings.HasPrefix(val, "A") {
return &godantic.Error{ErrType: "STARTS_WITH_A_ERR", Path: path, Message: "Field must start with A"}
}
return nil
})Apply it using:
type User struct {
Name *string `json:"name" validate:"starts_with_A"`
}Supports multiple tags per field!
🔌 Plugin-Based Validation
Godantic now supports embedded logic with:
type ValidationPlugin interface {
Validate() *godantic.Error
}Any struct that implements Validate() will be automatically invoked during validation. Works for nested fields and lists!
🔄 Dynamic Field Validation
Support for polymorphic or runtime-defined fields with:
type DynamicFieldsValidator interface {
GetValue() any
GetValueType() string
GetAttribute() string
}Let your structs declare how they should be validated at runtime — ideal for schema-driven forms, rules, or input engines.
⚙️ Improvements
- Refactored validation flow for better performance and modularity.
- Supports pointers, nested fields, arrays, enums, regex, formats, and conditions (
when:). - Enhanced path resolution for more accurate error messages.
📚 Documentation
All docs are now available in the new docs/ folder, ready for GitHub Pages or your static site generator.
🏁 Getting Started
go get github.com/grahms/godanticThen explore docs/getting-started.md or the README for full examples.
v1.4.0 — Precision & Power
📦 godantic v1.4.0 — Precision & Power
Release Date: 2025-04-03
Author: Ismael GraHms
Tag: v1.4.0
🚀 Highlights
This release introduces advanced numeric and decimal validation, enabling more expressive constraints directly via struct tags. It marks a major milestone in making godantic a robust, production-ready validation library — with native support for common real-world scenarios like monetary values, pagination limits, and constrained ranges.
✨ New Features
🔢 Generic Range Constraints
minandmaxfor:- Strings (length)
- Slices (length)
- Numeric values
⚖️ Numeric Boundaries
gt/lt: Greater than / Less thange/le: Greater than or equal / Less than or equal
🎯 Multiples
multiple_of: Value must be a clean multiple of a given number (e.g.,0.05,100)
🧮 Decimal Precision
max_digits: Maximum total digits (before + after decimal)decimal_places: Maximum digits after decimal
☢️ Special Float Handling
allow_inf_nan: Accepts+Inf,-Inf, andNaNwhen explicitly enabled
🧪 Test Coverage
- ✅ Full unit tests for all new validation rules
- Edge case handling for:
- Negative numbers
- Floats with trailing/leading zeroes
- Empty/nil fields
- Boundary limits
📚 Documentation
- Updated README with:
- Full tag matrix
- Code examples
- Tag semantics and type compatibility
Conditional Validation Based on Enum Values
🔹 Godantic Release Notes - Version 1.3.0
🚀 New Feature: Conditional Validation Based on Enum Values 🚀
🔹 What's New?
✅ Conditional Field Validation Using the when Tag
- Fields can now be validated only when another field has a specific value.
- Example:
🔹
type User struct { RegNo *string `json:"reg_no" when:"context.type=organization;binding=required"` }reg_nois required only whencontext.typeis"organization".
✅ Support for Multiple Conditions
- You can define multiple dependent fields in a single
whentag. - Example:
🔹
type Business struct { VATNumber *string `json:"vat_number" when:"context.type=business;context.country=EU;binding=required"` }vat_numberis required only whencontext.type=businessANDcontext.country=EU.
✅ Operator Support
Currently, the = operator is supported for exact matches:
| Operator | Example | Meaning |
|---|---|---|
| = | context.type=business | Field must be equal to value |
🔧 Improvements & Fixes
✅ Optimized validation performance with precomputed enum value maps.
✅ Fixed = prefix issue in parseCondition(), ensuring values are extracted correctly.
✅ Clearer error messages when a required field is missing due to a condition.
📌 Example Usage
Valid JSON Input
{
"context": { "type": "organization" },
"user": { "reg_no": "56789" }
}
✅ Passes validation because reg_no is provided for organization.
Invalid JSON Input
{
"context": { "type": "organization" },
"user": {}
}
❌ Fails validation with:
Field <user.reg_no> is required when context.type=organization
📢 Upgrade Guide
To upgrade your project to this version, update godantic using:
go get -u github.com/grahms/godantic
Then, update your structs to use the new when tag for conditional validation.
🔮 What's Next?
🟢 Support for additional operators (!=, >, <, >=, <=)
🟢 More binding options (regex, ignore, default)
🟢 Better structured error reporting
💡 Feedback & Contributions
Have suggestions or improvements? Open an issue or PR on GitHub.
🚀 Enjoy better validation with godantic! 🚀
🔹 What's New?
✅ Conditional Field Validation Using the when Tag
- Fields can now be validated only when another field has a specific value.
- Example:
🔹
type User struct { RegNo *string `json:"reg_no" when:"context.type=organization;binding=required"` }
reg_nois required only whencontext.typeis"organization".
✅ Support for Multiple Conditions
- You can define multiple dependent fields in a single
whentag. - Example:
🔹
type Business struct { VATNumber *string `json:"vat_number" when:"context.type=business;context.country=EU;binding=required"` }
vat_numberis required only whencontext.type=businessANDcontext.country=EU.
✅ Operator Support
Currently, the = operator is supported for exact matches:
| Operator | Example | Meaning |
|---|---|---|
= |
context.type=business |
Field must be equal to value |
🔧 Improvements & Fixes
✅ Optimized validation performance with precomputed enum value maps.
✅ Clearer error messages when a required field is missing due to a condition.
📌 Example Usage
Valid JSON Input
{
"context": { "type": "organization" },
"user": { "reg_no": "56789" }
}✅ Passes validation because reg_no is provided for organization.
Invalid JSON Input
{
"context": { "type": "organization" },
"user": {}
}❌ Fails validation with:
Field <user.reg_no> is required when context.type=organization
📢 Upgrade Guide
To upgrade your project to this version, update godantic using:
go get -u github.com/grahms/godanticThen, update your structs to use the new when tag for conditional validation.
🔮 What's Next?
🟢 Support for additional operators (!=, >, <, >=, <=)
🟢 More binding options (regex, ignore, default)
🟢 Better structured error reporting
💡 Feedback & Contributions
Have suggestions or improvements? Open an issue or PR on [GitHub](https://github.com/grahms/godantic).
🚀 Enjoy better validation with godantic! 🚀
explicitly ignore empty field
Merge pull request #16 from GraHms/feat/ignore-empty-by-field feat: explicitly ignore-empty values by field
Dynamic Fields validation
v1.1.0 feat: dynamic fields validation
user level custom validation
Merge pull request #15 from GraHms/feat/set-default feat: user custom validation
v1.0.11
v1.0.10: Merge pull request #11 from GraHms/feat/regex-validation
Overview
This release of Godantic has the capabilities of validating regex pattern matching, and format validation.
Format Tags
Godantic supports the following format tags for format validation:
- url
- date
- time
- uuid
- ip
- credit_card
- postal_code
- phone
- ssn
- credit_card_expiry
- latitude
- longitude
- hex_color
- mac_address
- mz-msisdn
- mz-nuit
Error Types
New types are provided for different validation scenarios, including:
- INVALID_REGEX_ERR
- INVALID_FORMAT_ERR
License
Godantic is licensed under the MIT License.
This release marks a significant milestone in the development of Godantic, providing comprehensive validation capabilities for Go applications.