Fix fieldName to strip JSON tag options, matching JSONSchema - #219
Merged
Conversation
fieldName used a field's json tag value as-is for the CheckErrors map key. A field tagged json:"name,omitempty" produced the error key "name,omitempty" instead of "name", and json:"-" produced the literal key "-" instead of falling back to the Go field name. schema.go's jsonPropertyName already parsed json tags correctly (strips options, treats "-" as "no JSON name"), so CheckStruct's error keys and JSONSchema's property names disagreed for any field with tag options. fieldName now calls the same jsonPropertyName helper JSONSchema uses, falling back to the Go field name when the tag says json:"-" (a CheckErrors key always needs some name, unlike a schema property which can simply be omitted for such a field). Fixes #194 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 52 52
Lines 896 896
=========================================
Hits 896 896 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cinar
enabled auto-merge (squash)
September 5, 2026 16:31
…g-options # Conflicts: # CHANGELOG.md
cinar
added a commit
that referenced
this pull request
Sep 5, 2026
## Problem Every PR added its own bullet to `CHANGELOG.md`'s `## [Unreleased]` section, always inserting at (or near) the same spot. With PRs landing close together, that made this file a near-guaranteed merge conflict on every concurrent pull request — the exact problem `DOC.md` caused before #180 dropped it in favor of pkg.go.dev. This wasn't theoretical: it's what just happened resolving conflicts on #219–#222. Each conflict resolution round immediately conflicted again as the next PR merged, because every remaining branch's `### Fixed` entry inserted into the same place. ## Fix - Freeze the current `## [Unreleased]` section as a one-time snapshot (documenting the six P0 bugfixes plus the earlier accumulated Added/Changed/Removed entries) and add a note explaining the new policy at the top of the file. - Going forward, unreleased changes are covered by [GitHub Releases](https://github.com/cinar/checker/releases), whose notes are generated automatically from merged pull requests — no file to conflict on. `CHANGELOG.md` only gains a new entry when a version is actually tagged, added by hand from that release's generated notes (a maintainer decision, not a per-PR one). - Updated `CLAUDE.md`'s conventions section: PRs no longer touch `CHANGELOG.md`. No code changes; docs/process only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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
checker.go'sfieldNameuses a field'sjsontag value verbatim for theCheckErrorsmap key:A field tagged
json:"email,omitempty"produces the error key"email,omitempty"instead of"email". A field taggedjson:"-"produces the literal key"-".schema.go'sjsonPropertyNamealready handles this correctly (strips,omitempty-style options viastrings.Cut, treats"-"as "no JSON name"), soCheckStruct's error keys andJSONSchema's property names disagreed for any field with tag options — verified this before writing the fix.Fix
fieldNamenow calls the existingjsonPropertyNamehelper instead of duplicating (and getting wrong) its own parsing. WhenjsonPropertyNamereportsfalse(thejson:"-"case),fieldNamefalls back to the Go field name — aCheckErrorskey always needs some name, whereas a schema property can simply be omitted for such a field, so the two call sites intentionally handle that case differently.Testing
TestCheckStructCustomNameWithOptions(json:"name,omitempty"→ key"name") andTestCheckStructJSONIgnoredFieldFallsBackToFieldName(json:"-"→ key"Name").go vet,gosecclean.Fixes #194
🤖 Generated with Claude Code
https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i