Skip to content

chore: include usage attribution in customer data - #3135

Merged
turip merged 1 commit into
mainfrom
chore/include-usage-attribution-in-customer-data
Jul 23, 2025
Merged

turip merged 1 commit into
mainfrom
chore/include-usage-attribution-in-customer-data

Conversation

@turip

@turip turip commented Jul 23, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Invoice customer details now include extended fields such as unique identifier, legal name, tax identification, postal addresses, and required usage attribution mapping.
  • Refactor

    • The customer property in invoices has been updated to use the new extended customer details format, providing more comprehensive information on invoices.

@turip
turip requested a review from a team as a code owner July 23, 2025 09:06
@coderabbitai

coderabbitai Bot commented Jul 23, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new schema, BillingInvoiceCustomerExtendedDetails, was introduced to extend invoice customer details with OpenMeter-specific fields, notably a required usageAttribution property. The Invoice schema's customer property was updated to use this new type instead of the previous BillingParty. All relevant OpenAPI specs, TypeScript client schemas, and Go mapping logic were updated accordingly.

Changes

Files/Paths Change Summary
api/client/javascript/src/client/schemas.ts Added BillingInvoiceCustomerExtendedDetails schema/type; updated Invoice.customer type.
api/openapi.cloud.yaml, api/openapi.yaml Added new schema BillingInvoiceCustomerExtendedDetails; updated Invoice.customer reference.
api/spec/src/billing/invoices/org.tsp Added model BillingInvoiceCustomerExtendedDetails extending BillingParty with new field.
api/spec/src/billing/invoices/invoice.tsp Changed Invoice.customer property type to new extended details model.
openmeter/billing/httpdriver/invoice.go Updated mapInvoiceCustomerToAPI to return the new extended details type and map new fields.

Estimated code review effort

2 (~20 minutes)

Possibly related PRs

  • fix: notification issues/test message #2763: Modifies the same mapInvoiceCustomerToAPI function, but retains the original return type; both PRs alter the function and are related through changes in customer mapping logic.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@chrisgacsal chrisgacsal added the release-note/misc Miscellaneous changes label Jul 23, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
api/openapi.cloud.yaml (1)

11782-11811: Consider inheriting from BillingParty via allOf to avoid field duplication
id, name, taxId, and addresses are already defined in BillingParty.
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 Attribution

Keeps one canonical source for shared fields and cleanly composes OpenMeter-specific extensions.

api/openapi.yaml (1)

15825-15827: Redundant allOf wrapper around a single $ref

customer currently uses

allOf:
  - $ref: '#/components/schemas/BillingInvoiceCustomerExtendedDetails'

Wrapping a single reference in allOf adds 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

📥 Commits

Reviewing files that changed from the base of the PR and between e1a64f3 and 1011d29.

📒 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 BillingParty to BillingInvoiceCustomerExtendedDetails correctly 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 UsageAttribution field 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 BillingInvoiceCustomerExtendedDetails model correctly:

  • Extends BillingParty using the spread operator
  • Includes comprehensive documentation explaining its purpose
  • Uses appropriate annotations (@friendlyName, @summary)
  • Makes usageAttribution required, ensuring consistency across the API

The composition approach is clean and maintainable.

api/openapi.cloud.yaml (2)

11804-11805: Verify maxItems: 1 constraint for addresses
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.customer now references a new schema
Switching from BillingParty to BillingInvoiceCustomerExtendedDetails will break existing clients that deserialize strictly typed invoices. Ensure:

  1. Versioning / compatibility strategy is communicated.
  2. Client SDKs are regenerated and released in lock-step.
  3. API changelog highlights the new required usageAttribution field.
api/client/javascript/src/client/schemas.ts (3)

2543-2561: LGTM! Well-structured schema definition.

The new BillingInvoiceCustomerExtendedDetails schema is properly defined with clear documentation and consistent field types that match the corresponding Go struct definitions. The required usageAttribution field 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 verified

The mapInvoiceCustomerToAPI function in openmeter/billing/httpdriver/invoice.go (lines 645–652) explicitly sets the UsageAttribution field, and the Ent create/update layers enforce its presence (see the validation in ent/db/billinginvoice_create.go). All invoice creation and update paths populate this field.

No changes required.

Comment thread api/openapi.yaml Resolved
@turip
turip enabled auto-merge (squash) July 23, 2025 09:12
@turip
turip merged commit 3e8c048 into main Jul 23, 2025
@turip
turip deleted the chore/include-usage-attribution-in-customer-data branch July 23, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants