Skip to content

[validator] add JSON tags support - #1

Merged
capcom6 merged 1 commit into
masterfrom
validator/json-tags-support
Jan 13, 2026
Merged

[validator] add JSON tags support#1
capcom6 merged 1 commit into
masterfrom
validator/json-tags-support

Conversation

@capcom6

@capcom6 capcom6 commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced validation error messages to reference JSON field names instead of internal identifiers, improving clarity in error reporting.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 13, 2026

Copy link
Copy Markdown

Walkthrough

The validator initialization in validator.go was modified to register a custom TagNameFunc that derives validation error field names from JSON struct tags. Two imports (reflect and strings) were added to support this functionality, while maintaining the existing function signature.

Changes

Cohort / File(s) Summary
Validator TagNameFunc Registration
validator.go
Added reflect and strings imports. Modified the New() function to register a custom TagNameFunc that maps struct field validation errors to their JSON tag names (excluding "-" values), improving error reporting clarity.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding JSON tags support to the validator by registering a TagNameFunc that maps JSON field names for validation error reporting.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b55dc1 and 5858f81.

📒 Files selected for processing (1)
  • validator.go
🔇 Additional comments (2)
validator.go (2)

3-8: LGTM!

All imports are necessary and correctly used: reflect for the StructField type, strings for parsing the tag, and the validator package.


16-24: Clean and idiomatic implementation of JSON tag extraction.

The code correctly handles:

  • Fields with JSON tags (e.g., json:"name,omitempty") → extracts name
  • Excluded fields (json:"-") → returns "" allowing fallback to struct field name
  • Fields without JSON tags → returns "" allowing fallback to struct field name

The WithRequiredStructEnabled() and RegisterTagNameFunc() APIs are valid in go-playground/validator v10.28.0 and are used correctly here.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@capcom6
capcom6 merged commit 731993b into master Jan 13, 2026
4 checks passed
@capcom6
capcom6 deleted the validator/json-tags-support branch January 13, 2026 13:21
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.

1 participant