[11/11] Support validate tag as a fallback for checkers tag - #234
Merged
Conversation
cinar
force-pushed
the
p1-11-validate-alias
branch
from
September 5, 2026 17:42
f02b9ea to
71b3c48
Compare
go-playground/validator has trained the ecosystem to reach for a tag named "validate". Migrating a codebase already tagged that way to Checker meant renaming every struct tag just to get picked up, even when the tag's contents were already Checker-compatible syntax. Add fieldConfig, which reads the checkers tag if present (via Tag.Lookup, so an explicit, empty checkers:"" is honored as "no checks" rather than falling through) and falls back to the validate tag otherwise. Wired into both CheckStruct and JSONSchema's structSchema, the two places that previously read field.Tag.Get( checkerTag) directly, so the fallback behaves consistently for validation and schema generation. This does not give Checker any understanding of validator's own tag syntax (oneof=a b c, len=5, etc.) -- only the tag *name* is a fallback, not its contents. A struct has to already use Checker-compatible rules under that tag name for this to help; documented that distinction explicitly in the README so it isn't mistaken for real validator-syntax compatibility. Fixes #208 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
cinar
force-pushed
the
p1-11-validate-alias
branch
from
September 5, 2026 17:58
71b3c48 to
8a759de
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #234 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 64 64
Lines 1196 1200 +4
=========================================
+ Hits 1196 1200 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
go-playground/validatorhas trained the ecosystem to reach for a struct tag namedvalidate. Migrating a codebase already tagged that way to Checker meant renaming every struct tag just to get picked up, even when the tag's contents were already Checker-compatible syntax.Fix
Add
fieldConfig, which reads thecheckerstag if present (viaTag.Lookup, so an explicit, emptycheckers:""is honored as "no checks" rather than falling through) and falls back to thevalidatetag otherwise. Wired into bothCheckStructandJSONSchema'sstructSchema— the two places that previously readfield.Tag.Get(checkerTag)directly — so the fallback behaves consistently for validation and schema generation, not just one of them.Scope is intentionally narrow: this does not give Checker any understanding of
validator's own tag syntax (oneof=a b c,len=5, etc.) — only the tag name is a fallback, not its contents. A struct has to already use Checker-compatible rules under that tag name for this to help. Documented that distinction explicitly in the README so it isn't mistaken for real validator-syntax compatibility.Testing
validate_tag_test.go: fallback picks up both checks and normalizers, reports errors correctly,checkerstag takes precedence when both are present, an explicit emptycheckers:""does not fall back, and the fallback works throughJSONSchematoo.go vet,gosec,reviveclean.Fixes #208
Chain note: PR 11 of 11 — last one in this chain.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i