Repository navigation
chore: include usage attribution in customer data - #3135
Conversation
📝 WalkthroughWalkthroughA new schema, Changes
Estimated code review effort2 (~20 minutes) Possibly related PRs
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
api/openapi.cloud.yaml (1)
11782-11811: Consider inheriting fromBillingPartyviaallOfto avoid field duplication
id,name,taxId, andaddressesare already defined inBillingParty.
Redefining them here duplicates contract-level knowledge and increases maintenance cost/risk of divergent definitions.- BillingInvoiceCustomerExtendedDetails: - type: object - required: - - usageAttribution - properties: - id: - type: string - ... - addresses: - type: array - ... - usageAttribution: - allOf: - - $ref: '#/components/schemas/CustomerUsageAttribution' - description: Mapping to attribute metered usage to the customer - title: Usage Attribution + BillingInvoiceCustomerExtendedDetails: + allOf: + - $ref: '#/components/schemas/BillingParty' + - type: object + required: + - usageAttribution + properties: + usageAttribution: + allOf: + - $ref: '#/components/schemas/CustomerUsageAttribution' + description: Mapping to attribute metered usage to the customer + title: Usage AttributionKeeps one canonical source for shared fields and cleanly composes OpenMeter-specific extensions.
api/openapi.yaml (1)
15825-15827: RedundantallOfwrapper around a single$ref
customercurrently usesallOf: - $ref: '#/components/schemas/BillingInvoiceCustomerExtendedDetails'Wrapping a single reference in
allOfadds no semantic value and sometimes confuses schema generators (they treat it as an anonymous composed type).
Unless you intend to append more constraints alongside the reference, simplify to a direct$ref:- customer: - allOf: - - $ref: '#/components/schemas/BillingInvoiceCustomerExtendedDetails' + customer: + $ref: '#/components/schemas/BillingInvoiceCustomerExtendedDetails'
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
api/client/javascript/src/client/schemas.ts(3 hunks)api/openapi.cloud.yaml(2 hunks)api/openapi.yaml(2 hunks)api/spec/src/billing/invoices/invoice.tsp(1 hunks)api/spec/src/billing/invoices/org.tsp(1 hunks)openmeter/billing/httpdriver/invoice.go(1 hunks)
🧠 Learnings (2)
📓 Common learnings
Learnt from: chrisgacsal
PR: openmeterio/openmeter#2699
File: openmeter/productcatalog/planaddon/service/service_test.go:210-211
Timestamp: 2025-04-21T08:32:31.689Z
Learning: In `productcatalog.UsageBasedRateCard`, the `BillingCadence` field is a non-pointer `isodate.Period`, while in `productcatalog.FlatFeeRateCard`, `BillingCadence` is a pointer type (`*isodate.Period`). This means `MonthPeriod` should be used directly for `UsageBasedRateCard` (not `&MonthPeriod`).
openmeter/billing/httpdriver/invoice.go (1)
Learnt from: chrisgacsal
PR: #2699
File: openmeter/productcatalog/planaddon/service/service_test.go:210-211
Timestamp: 2025-04-21T08:32:31.689Z
Learning: In productcatalog.UsageBasedRateCard, the BillingCadence field is a non-pointer isodate.Period, while in productcatalog.FlatFeeRateCard, BillingCadence is a pointer type (*isodate.Period). This means MonthPeriod should be used directly for UsageBasedRateCard (not &MonthPeriod).
🧬 Code Graph Analysis (1)
api/client/javascript/src/client/schemas.ts (2)
api/api.gen.go (1)
BillingInvoiceCustomerExtendedDetails(1208-1224)api/client/go/client.gen.go (1)
BillingInvoiceCustomerExtendedDetails(1068-1084)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: chrisgacsal
PR: openmeterio/openmeter#2699
File: openmeter/productcatalog/planaddon/service/service_test.go:210-211
Timestamp: 2025-04-21T08:32:31.689Z
Learning: In `productcatalog.UsageBasedRateCard`, the `BillingCadence` field is a non-pointer `isodate.Period`, while in `productcatalog.FlatFeeRateCard`, `BillingCadence` is a pointer type (`*isodate.Period`). This means `MonthPeriod` should be used directly for `UsageBasedRateCard` (not `&MonthPeriod`).
openmeter/billing/httpdriver/invoice.go (1)
Learnt from: chrisgacsal
PR: #2699
File: openmeter/productcatalog/planaddon/service/service_test.go:210-211
Timestamp: 2025-04-21T08:32:31.689Z
Learning: In productcatalog.UsageBasedRateCard, the BillingCadence field is a non-pointer isodate.Period, while in productcatalog.FlatFeeRateCard, BillingCadence is a pointer type (*isodate.Period). This means MonthPeriod should be used directly for UsageBasedRateCard (not &MonthPeriod).
🧬 Code Graph Analysis (1)
api/client/javascript/src/client/schemas.ts (2)
api/api.gen.go (1)
BillingInvoiceCustomerExtendedDetails(1208-1224)api/client/go/client.gen.go (1)
BillingInvoiceCustomerExtendedDetails(1068-1084)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Artifacts / Container image
- GitHub Check: Artifacts / Benthos Collector Container image
- GitHub Check: CI
- GitHub Check: Quickstart
- GitHub Check: E2E
- GitHub Check: Lint
- GitHub Check: Developer environment
- GitHub Check: Commit hooks
- GitHub Check: Test
- GitHub Check: Build
- GitHub Check: Migration Checks
- GitHub Check: Analyze (go)
🔇 Additional comments (8)
api/spec/src/billing/invoices/invoice.tsp (1)
72-72: LGTM! Type change aligns with PR objectives.The update from
BillingPartytoBillingInvoiceCustomerExtendedDetailscorrectly implements the requirement to include usage attribution in customer data.openmeter/billing/httpdriver/invoice.go (1)
642-651: Excellent implementation of the extended customer details.The function correctly:
- Updates the return type to match the new API specification
- Maps the
UsageAttributionfield from the internal customer data- Preserves all existing field mappings without breaking changes
The implementation is clean and consistent with the PR objectives.
api/spec/src/billing/invoices/org.tsp (1)
60-74: Well-designed model extension following TypeSpec best practices.The
BillingInvoiceCustomerExtendedDetailsmodel correctly:
- Extends
BillingPartyusing the spread operator- Includes comprehensive documentation explaining its purpose
- Uses appropriate annotations (
@friendlyName,@summary)- Makes
usageAttributionrequired, ensuring consistency across the APIThe composition approach is clean and maintainable.
api/openapi.cloud.yaml (2)
11804-11805: VerifymaxItems: 1constraint foraddresses
Limiting a customer to a single postal address might be too restrictive (e.g., HQ + billing address). Confirm this with product requirements.
15465-15469: Potential breaking change:Invoice.customernow references a new schema
Switching fromBillingPartytoBillingInvoiceCustomerExtendedDetailswill break existing clients that deserialize strictly typed invoices. Ensure:
- Versioning / compatibility strategy is communicated.
- Client SDKs are regenerated and released in lock-step.
- API changelog highlights the new required
usageAttributionfield.api/client/javascript/src/client/schemas.ts (3)
2543-2561: LGTM! Well-structured schema definition.The new
BillingInvoiceCustomerExtendedDetailsschema is properly defined with clear documentation and consistent field types that match the corresponding Go struct definitions. The requiredusageAttributionfield appropriately captures OpenMeter-specific billing requirements.
10403-10404: LGTM! Proper export type alias addition.The export follows the established naming convention and structure, enabling external usage of the new schema type.
2587-2587: Invoice customer usageAttribution mapping verifiedThe
mapInvoiceCustomerToAPIfunction inopenmeter/billing/httpdriver/invoice.go(lines 645–652) explicitly sets theUsageAttributionfield, and the Ent create/update layers enforce its presence (see the validation inent/db/billinginvoice_create.go). All invoice creation and update paths populate this field.No changes required.
Summary by CodeRabbit
New Features
Refactor