Support struct tags for map keys - #311
Conversation
📝 WalkthroughWalkthroughThis pull request introduces support for using struct tags to determine destination map keys during struct-to-map conversion. It adds a new configuration option Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
437eaf9 to
5c14736
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
issue255_test.go (1)
9-14: Consider adding an explicitjson:""fallback case.The implementation supports empty-tag fallback too; adding one field/assertion would lock that behavior down.
Proposed test extension
type issue255Person struct { FirstName string `json:"first_name"` LastName string `json:"last_name,omitempty"` Password string `json:"-"` + Nickname string `json:""` Age int } @@ person := issue255Person{ FirstName: "Ada", LastName: "Lovelace", Password: "secret", + Nickname: "Countess", Age: 36, } @@ if actual["password"] != "secret" { t.Fatalf("expected '-' tag to fall back to default field name, got %#v", actual) } + if actual["nickname"] != "Countess" { + t.Fatalf("expected empty tag name to fall back to default field name, got %#v", actual) + } if actual["age"] != 36 { t.Fatalf("expected untagged field to fall back to default field name, got %#v", actual) }Also applies to: 29-40
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@issue255_test.go` around lines 9 - 14, The test should include an explicit field on the issue255Person struct that uses the empty-tag fallback (e.g., add a new field with `json:""` tag) and an assertion verifying that encoding/decoding uses the fallback behavior; update the test cases that exercise issue255Person (the assertions around lines covering the encoding/decoding, referenced by the struct and existing checks at lines ~29-40) to include expected JSON key/name for that new field to lock in the empty-tag behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@issue255_test.go`:
- Around line 9-14: The test should include an explicit field on the
issue255Person struct that uses the empty-tag fallback (e.g., add a new field
with `json:""` tag) and an assertion verifying that encoding/decoding uses the
fallback behavior; update the test cases that exercise issue255Person (the
assertions around lines covering the encoding/decoding, referenced by the struct
and existing checks at lines ~29-40) to include expected JSON key/name for that
new field to lock in the empty-tag behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9b869b4c-0b98-4e45-b475-95850b428f65
📒 Files selected for processing (3)
issue255_test.gomap.gomerge.go
/claim #255
Summary
WithMapKeyTag(tag)for struct-to-map mapping.json:"name,omitempty".-.Validation
go test ./...git diff --checkSummary by CodeRabbit
Release Notes