Repository navigation
fix(api): serialize empty addon rate cards as [] instead of null - #5110
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe conversion now serializes empty billing rate-card collections as empty JSON arrays. Tests cover direct rate-card conversion and add-ons without rate cards. ChangesBilling rate-card conversion
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Merge Risk: ⚪ Minimal · up to 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)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
e983888 to
164dc68
Compare
164dc68 to
aefe7ab
Compare
aefe7ab to
3e3f451
Compare
What
Removes a nil early-return from the v3 addons response converter so
rateCardsis always serialized as a JSON array. Adds two unit tests pinning the empty-input behavior ([], notnull).Why
ToAPIBillingRateCardsreturnednil, nilwhen the add-on had no rate cards, which marshals to"rateCards": null. The v3 API schema declaresrateCardsas 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) expectRateCard[]and crash onnull- readingrateCards.lengththrows.How
api/v3/handlers/addons/convert.go: delete thelen(rcs) == 0 → nilshortcut. The loop below already builds the slice withmake(..., 0, len(rcs)), so empty input now yields an empty (non-nil) slice that marshals to[].api/v3/handlers/addons/convert_test.go: addTestToAPIBillingRateCards_EmptyInputandTestToAPIAddon_EmptyRateCardsassertingNotNil+Emptyand that the marshaled JSON contains"rate_cards":[].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_cardsvalidation error invalidation_errors- only the serialization changed.Summary by CodeRabbit
Bug Fixes
null.Tests
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
ToAPIBillingRateCardsto return an initialized empty slice for empty input.Reviews (4) · Last reviewed commit: "fix(api): serialize empty addon rate car..."