Add JSON tags to structs and configure SQLC for custom Go types - #52
Conversation
- Add `json` tags to all relevant structs for consistent API compatibility. - Update `sqlc.yml` to enable JSON tags and define custom Go types for PostgreSQL types (e.g., `timestamp`, `uuid`, `text`). - Regenerate SQLC files to reflect updated configurations and include JSON tags in generated code. - Update example JSON payloads in Bruno collections to align with new tag format (lowercase keys).
📝 WalkthroughWalkthroughEnable sqlc JSON tag emission and type overrides, regenerate Go models/params with snake_case ChangesAPI Response Field Naming Consistency
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/platform/platforms.sql.gen.go`:
- Around line 90-94: The JSON tag for the Updatedat field in the
UpdatePlatformParams struct is using "updatedat" instead of snake_case
"updated_at", breaking request binding; update the struct tag on Updatedat to
json:"updated_at" (and any other generated structs with Updatedat at lines
~101-102) and then fix the originating SQL arg name to snake_case and re-run the
codegen so all generated types (e.g., UpdatePlatformParams and the other
generated param structs that contain Updatedat) consistently use "updated_at".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 26ca9f62-d501-4a3c-b4ed-0948ffc9ac27
📒 Files selected for processing (9)
_bruno/Platform/All Platforms.yml_bruno/Platform/Platform By Id.yml_bruno/Product/Get Product By ID.yml_bruno/Product/Get Products By Platform.ymlinternal/platform/models.gen.gointernal/platform/platforms.sql.gen.gointernal/product/models.gen.gointernal/product/products.sql.gen.gosqlc.yml
- Rename `Updatedat` to `UpdatedAt` in all relevant structs, queries, and tests to maintain consistency with naming conventions. - Update SQLC-generated files to reflect the changes.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/platform/handler_test.go (1)
499-503: ⚡ Quick winAdd explicit snake_case response-key assertions to lock the PR objective.
Current handler tests mostly unmarshal into structs, which won’t reliably catch key-shape regressions. Add raw JSON assertions (for example in GET success cases) for keys like
id,created_at, andupdated_at.As per coding guidelines, "**/*_test.go`: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/platform/handler_test.go` around lines 499 - 503, The tests currently only assert struct fields (e.g., arg.UpdatedAt) which won’t catch JSON key-shape regressions; update the GET success-case tests in internal/platform/handler_test.go to also unmarshal the raw response into a map[string]json.RawMessage (or map[string]interface{}) and assert the presence of the snake_case keys "id", "created_at", and "updated_at" (in addition to the existing arg.UpdatedAt checks) so the test fails if those keys are missing or renamed; locate the GET success-case code near the existing arg.UpdatedAt assertions and add those raw JSON key existence assertions using the response body bytes from the test recorder.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/platform/handler_test.go`:
- Around line 499-503: The tests currently only assert struct fields (e.g.,
arg.UpdatedAt) which won’t catch JSON key-shape regressions; update the GET
success-case tests in internal/platform/handler_test.go to also unmarshal the
raw response into a map[string]json.RawMessage (or map[string]interface{}) and
assert the presence of the snake_case keys "id", "created_at", and "updated_at"
(in addition to the existing arg.UpdatedAt checks) so the test fails if those
keys are missing or renamed; locate the GET success-case code near the existing
arg.UpdatedAt assertions and add those raw JSON key existence assertions using
the response body bytes from the test recorder.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 72b13ec3-f522-4a5f-aab5-7254413ed945
📒 Files selected for processing (5)
internal/platform/handler_test.gointernal/platform/platforms.sqlinternal/platform/platforms.sql.gen.gointernal/platform/request.gointernal/platform/request_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- internal/platform/platforms.sql.gen.go
jsontags to all relevant structs for consistent API compatibility.sqlc.ymlto enable JSON tags and define custom Go types for PostgreSQL types (e.g.,timestamp,uuid,text).Description
Code Rabbit Summary
Summary by CodeRabbit
Fixes
Closes #47
Post Deployment Tasks?