Skip to content

fix(subscription): preserve item JSON fields - #4901

Merged
GAlexIHU merged 1 commit into
mainfrom
codex/fix-subscription-item-json
Aug 10, 2026
Merged

GAlexIHU merged 1 commit into
mainfrom
codex/fix-subscription-item-json

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • deserialize regular SubscriptionItem fields through a type alias instead of a manually mirrored struct
  • keep polymorphic rate-card decoding isolated to the rateCard field
  • cover annotations, both concrete rate-card types, and unknown discriminators

Why

The custom JSON decoder manually copied every subscription item field. Fields added later, such as annotations, were serialized but silently lost during deserialization. Using the item shape itself prevents the decoder from drifting as the model evolves.

Validation

  • nix develop --impure .#ci -c env POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./openmeter/subscription -count=1

Summary by CodeRabbit

  • Bug Fixes
    • Improved subscription item deserialization for usage-based and flat-fee rate cards.
    • Preserved annotations during subscription item serialization and deserialization.
    • Added validation to reject unknown rate card types with clear errors.

Greptile Summary

This PR prevents regular SubscriptionItem JSON fields from being dropped by decoding through an alias while handling the polymorphic rate card separately.

  • Preserves fields such as annotations without maintaining a mirrored decoding struct.
  • Supports both flat-fee and usage-based rate cards.
  • Adds round-trip and unknown-discriminator test coverage.

Confidence Score: 5/5

The PR appears safe to merge with no actionable correctness or security issues identified.

The alias-based decoder preserves ordinary subscription item fields, isolates polymorphic rate-card decoding, and retains validation for both supported and unknown rate-card discriminators.

Important Files Changed

Filename Overview
openmeter/subscription/item.go Refactors custom JSON decoding to preserve the complete item shape while retaining concrete rate-card discriminator validation.
openmeter/subscription/serialize_test.go Extends round-trip coverage to annotations and both supported rate-card types, and verifies rejection of unknown discriminators.

Reviews (1): Last reviewed commit: "fix(subscription): preserve item JSON fi..." | Re-trigger Greptile

Context used:

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review 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: Pro Plus

Run ID: 0c7cdcad-f9ef-48fb-8ea5-b941efc63923

📥 Commits

Reviewing files that changed from the base of the PR and between bc12204 and 2fcf841.

📒 Files selected for processing (2)
  • openmeter/subscription/item.go
  • openmeter/subscription/serialize_test.go

📝 Walkthrough

Walkthrough

SubscriptionItem JSON deserialization now uses an alias and polymorphic rate card decoding. Tests cover annotations, shared fields, flat-fee and usage-based rate cards, round trips, and unknown rate card types.

Changes

Subscription item serialization

Layer / File(s) Summary
Polymorphic rate card deserialization
openmeter/subscription/item.go
UnmarshalJSON decodes complete item data and delegates rateCard decoding. The helper selects flat-fee or usage-based implementations and rejects unknown types.
Serialization round-trip validation
openmeter/subscription/serialize_test.go
Tests cover annotations, shared fields, both rate card types, round trips, and unknown rate card types.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: turip

Sequence Diagram(s)

sequenceDiagram
  participant Item as SubscriptionItem.UnmarshalJSON
  participant Decoder as unmarshalSubscriptionItemRateCard
  participant Card as FlatFeeRateCard/UsageBasedRateCard
  Item->>Decoder: pass raw rateCard JSON
  Decoder->>Card: select and unmarshal concrete rate card
  Card-->>Decoder: return decoded rate card
  Decoder-->>Item: assign rate card or return error
Loading
🚥 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 describes the main change: preserving subscription item JSON fields during deserialization.
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 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-subscription-item-json

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.

@GAlexIHU GAlexIHU added the release-note/bug-fix Release note: Bug Fixes label Aug 10, 2026
@GAlexIHU
GAlexIHU marked this pull request as ready for review August 10, 2026 15:49
@GAlexIHU
GAlexIHU requested a review from a team as a code owner August 10, 2026 15:49
@GAlexIHU
GAlexIHU enabled auto-merge (squash) August 10, 2026 15:53
@GAlexIHU
GAlexIHU merged commit f5d9efe into main Aug 10, 2026
28 of 29 checks passed
@GAlexIHU
GAlexIHU deleted the codex/fix-subscription-item-json branch August 10, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants