Skip to content

Add JSON tags to structs and configure SQLC for custom Go types - #52

Merged
jlpdeveloper merged 2 commits into
mainfrom
update-return-values
May 7, 2026
Merged

Add JSON tags to structs and configure SQLC for custom Go types#52
jlpdeveloper merged 2 commits into
mainfrom
update-return-values

Conversation

@jlpdeveloper

@jlpdeveloper jlpdeveloper commented May 7, 2026

Copy link
Copy Markdown
Contributor
  • 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).

Description

Code Rabbit Summary

Summary by CodeRabbit

  • Style
    • API examples and sample responses updated to use consistent snake_case JSON field names across platform and product endpoints (e.g., id, platform_id, created_at, updated_at) replacing prior PascalCase keys in documented responses.

Fixes

Closes #47

Post Deployment Tasks?

- 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).
@jlpdeveloper jlpdeveloper added this to the Phase 2: API Endpoints milestone May 7, 2026
@jlpdeveloper jlpdeveloper self-assigned this May 7, 2026
@jlpdeveloper jlpdeveloper added skip-changelog Won't be added to the release notes chore refactor, maintenance, etc. labels May 7, 2026
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Enable sqlc JSON tag emission and type overrides, regenerate Go models/params with snake_case json:"..." tags, fix UpdatedAt casing and SQL param naming, and update API example responses and tests to use snake_case.

Changes

API Response Field Naming Consistency

Layer / File(s) Summary
Code Generation Configuration
sqlc.yml
Enabled emit_json_tags: true and added PostgreSQL type overrides for internal/platform and internal/product.
Platform Models
internal/platform/models.gen.go, internal/platform/platforms.sql.gen.go
Added JSON struct tags to Flow, FlowStep, Platform, and Product model structs; updated CreatePlatformParams/UpdatePlatformParams with JSON tags and field renames.
SQL / Handler Wiring
internal/platform/platforms.sql, internal/platform/platforms.sql.gen.go, internal/platform/request.go
UpdatePlatform SQL now uses @updated_at; generated QueryRow wiring and updatePlatformRequest.ToParams set UpdatedAt correctly.
Product Models
internal/product/models.gen.go, internal/product/products.sql.gen.go
Added JSON struct tags to Flow, FlowStep, Platform, and Product model structs; updated CreateProductParams/UpdateProductParams with JSON tags.
API Documentation / Examples
_bruno/Platform/All Platforms.yml, _bruno/Platform/Platform By Id.yml, _bruno/Product/Get Product By ID.yml, _bruno/Product/Get Products By Platform.yml
Example 200 responses changed from PascalCase keys to snake_case keys (IDid, Namename, CreatedAtcreated_at, etc.).
Tests
internal/platform/handler_test.go, internal/platform/request_test.go
Tests updated to assert UpdatedAt.Valid and use UpdatedAt.Time; one diff hunk contains stray numeric lines that may be accidental.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I nibble tags and hop in glee,

swapping cases for consistency.
Now responses hum in snake_case tune,
tests and docs align by noon. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding JSON tags to structs and configuring SQLC for custom Go types, which directly addresses the root cause of the inconsistency described in the linked issue.
Linked Issues check ✅ Passed The PR successfully addresses issue #47's requirement to use snake_case JSON fields consistently across all API responses by configuring SQLC to generate json tags and updating both generated code and example payloads.
Out of Scope Changes check ✅ Passed All changes directly support the objective of standardizing API field naming to snake_case: SQLC configuration, struct tag generation, SQL parameter updates, and Bruno documentation examples are all scope-appropriate.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update-return-values

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.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8118e2c and 7cf5343.

📒 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.yml
  • internal/platform/models.gen.go
  • internal/platform/platforms.sql.gen.go
  • internal/product/models.gen.go
  • internal/product/products.sql.gen.go
  • sqlc.yml

Comment thread internal/platform/platforms.sql.gen.go
- 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
internal/platform/handler_test.go (1)

499-503: ⚡ Quick win

Add 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, and updated_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

📥 Commits

Reviewing files that changed from the base of the PR and between 7cf5343 and 4509a3d.

📒 Files selected for processing (5)
  • internal/platform/handler_test.go
  • internal/platform/platforms.sql
  • internal/platform/platforms.sql.gen.go
  • internal/platform/request.go
  • internal/platform/request_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/platform/platforms.sql.gen.go

@jlpdeveloper
jlpdeveloper merged commit a3d607f into main May 7, 2026
3 checks passed
@jlpdeveloper
jlpdeveloper deleted the update-return-values branch May 7, 2026 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore refactor, maintenance, etc. skip-changelog Won't be added to the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Return Payloads to use Snake Case

1 participant