Skip to content

fix(api): serialize empty addon rate cards as [] instead of null - #5110

Merged
borbelyr-kong merged 1 commit into
mainfrom
fix/addon-empty-rate-cards
Sep 10, 2026
Merged

borbelyr-kong merged 1 commit into
mainfrom
fix/addon-empty-rate-cards

Conversation

@borbelyr-kong

@borbelyr-kong borbelyr-kong commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What

Removes a nil early-return from the v3 addons response converter so rateCards is always serialized as a JSON array. Adds two unit tests pinning the empty-input behavior ([], not null).

Why

ToAPIBillingRateCards returned nil, nil when the add-on had no rate cards, which marshals to "rateCards": null. The v3 API schema declares rateCards as a required, non-nullable array, so every addon endpoint (create, get, list, update, publish, archive) violated the contract for freshly created draft add-ons. Typed clients generated from the schema (e.g. @openmeter/client) expect RateCard[] and crash on null - reading rateCards.length throws.

How

  • api/v3/handlers/addons/convert.go: delete the len(rcs) == 0 → nil shortcut. The loop below already builds the slice with make(..., 0, len(rcs)), so empty input now yields an empty (non-nil) slice that marshals to [].
  • api/v3/handlers/addons/convert_test.go: add TestToAPIBillingRateCards_EmptyInput and TestToAPIAddon_EmptyRateCards asserting NotNil + Empty and that the marshaled JSON contains "rate_cards":[].
  • Input-side FromAPI* converters and the TypeSpec spec are untouched - the spec was already correct; this fixes the implementation to match it.

This mirrors the plans handler (ToAPIBillingPlanPhase), which already initializes its rate-card slice to an empty slice for the same reason.

Note: draft add-ons still surface the addon_has_no_rate_cards validation error in validation_errors - only the serialization changed.

Summary by CodeRabbit

  • Bug Fixes

    • Empty billing rate-card collections now return as empty JSON arrays instead of null.
    • Add-on responses consistently represent empty rate-card lists as non-null arrays.
  • Tests

    • Added coverage for empty billing rate-card and add-on conversions.

RetriggerConfidence Score: 5/5

The PR appears safe to merge because the converter now matches the existing API schema and the behavior is covered at both conversion and response-serialization levels.

Summary

  • Updates ToAPIBillingRateCards to return an initialized empty slice for empty input.
  • Adds focused converter and full add-on serialization tests covering the empty collection behavior.

Reviews (4) · Last reviewed commit: "fix(api): serialize empty addon rate car..."

@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 6ed4d84a-c651-428e-9299-2fe799c9b97c

📥 Commits

Reviewing files that changed from the base of the PR and between e983888 and 164dc68.

📒 Files selected for processing (1)
  • api/v3/handlers/addons/convert.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The conversion now serializes empty billing rate-card collections as empty JSON arrays. Tests cover direct rate-card conversion and add-ons without rate cards.

Changes

Billing rate-card conversion

Layer / File(s) Summary
Empty rate-card conversion and coverage
api/v3/handlers/addons/convert.go, api/v3/handlers/addons/convert_test.go
ToAPIBillingRateCards returns a non-nil empty slice for empty input. Tests verify [] output for rate-card lists and add-ons without rate cards.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: tothandras, chrisgacsal, rolosp

Merge Risk: ⚪ Minimal · up to 3e3f4

Empty add-on rate-card collections now serialize as [] rather than null, with coverage for direct conversion and add-on API serialization. No actionable current-head merge risk remains.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: empty add-on rate cards serialize as [] instead of null.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 fix/addon-empty-rate-cards

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.

@borbelyr-kong

Copy link
Copy Markdown
Contributor Author

@greptileai

@borbelyr-kong
borbelyr-kong force-pushed the fix/addon-empty-rate-cards branch from e983888 to 164dc68 Compare September 9, 2026 16:40
@borbelyr-kong
borbelyr-kong marked this pull request as ready for review September 9, 2026 18:32
@borbelyr-kong
borbelyr-kong requested a review from a team as a code owner September 9, 2026 18:32
@borbelyr-kong
borbelyr-kong force-pushed the fix/addon-empty-rate-cards branch from 164dc68 to aefe7ab Compare September 10, 2026 07:43
@borbelyr-kong
borbelyr-kong force-pushed the fix/addon-empty-rate-cards branch from aefe7ab to 3e3f451 Compare September 10, 2026 07:50
@borbelyr-kong
borbelyr-kong merged commit 4cd38dd into main Sep 10, 2026
42 of 48 checks passed
@borbelyr-kong
borbelyr-kong deleted the fix/addon-empty-rate-cards branch September 10, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants