Skip to content

[11/11] Support validate tag as a fallback for checkers tag - #234

Merged
cinar merged 1 commit into
mainfrom
p1-11-validate-alias
Sep 5, 2026
Merged

[11/11] Support validate tag as a fallback for checkers tag#234
cinar merged 1 commit into
mainfrom
p1-11-validate-alias

Conversation

@cinar

@cinar cinar commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Problem

go-playground/validator has trained the ecosystem to reach for a struct 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.

Fix

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, 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, checkers tag takes precedence when both are present, an explicit empty checkers:"" does not fall back, and the fallback works through JSONSchema too.
  • Full suite passes, 100% coverage maintained.
  • go vet, gosec, revive clean.

Fixes #208


Chain note: PR 11 of 11 — last one in this chain.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i

@cinar
cinar force-pushed the p1-11-validate-alias branch from f02b9ea to 71b3c48 Compare September 5, 2026 17:42
@cinar
cinar changed the base branch from p1-10-len to main September 5, 2026 17:55
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
cinar force-pushed the p1-11-validate-alias branch from 71b3c48 to 8a759de Compare September 5, 2026 17:58
@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fde13bb) to head (8a759de).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cinar
cinar merged commit 2cdc4bb into main Sep 5, 2026
8 checks passed
@cinar
cinar deleted the p1-11-validate-alias branch September 5, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support validate tag as a fallback alias for checkers tag

1 participant