Skip to content

feat(api): add-ons v3 - #4138

Merged
tothandras merged 3 commits into
mainfrom
feat/addons-v3
Apr 20, 2026
Merged

tothandras merged 3 commits into
mainfrom
feat/addons-v3

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Apr 15, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • New Features
    • Added API v3 endpoints for full add-on lifecycle: create, retrieve, list, update, delete, archive, and publish.
    • Enabled paginated add-on listing with page size and navigation controls.
    • Added comprehensive add-on billing support: rate cards, multiple pricing models, tax and discount configuration.
  • Chores
    • v3 server now wires and exposes the add-ons API surface.

@coderabbitai

coderabbitai Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6fde3194-e824-4144-8b38-5b287dbebc0d

📥 Commits

Reviewing files that changed from the base of the PR and between 4e03bdf and 784db05.

📒 Files selected for processing (12)
  • api/v3/handlers/addons/archive.go
  • api/v3/handlers/addons/convert.go
  • api/v3/handlers/addons/create.go
  • api/v3/handlers/addons/delete.go
  • api/v3/handlers/addons/get.go
  • api/v3/handlers/addons/handler.go
  • api/v3/handlers/addons/list.go
  • api/v3/handlers/addons/publish.go
  • api/v3/handlers/addons/update.go
  • api/v3/server/routes.go
  • api/v3/server/server.go
  • openmeter/server/server.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • openmeter/server/server.go
  • api/v3/server/routes.go
  • api/v3/handlers/addons/delete.go
  • api/v3/handlers/addons/archive.go
  • api/v3/handlers/addons/publish.go
  • api/v3/handlers/addons/list.go
  • api/v3/server/server.go

📝 Walkthrough

Walkthrough

Adds a new API v3 add‑ons surface: handlers for create/read/update/list/delete/publish/archive, a conversion module mapping domain ↔ API models (extensive billing/rate‑card logic), and server wiring to expose the addon service through the v3 server.

Changes

Cohort / File(s) Summary
Addons handlers
api/v3/handlers/addons/{create,update,get,delete,list,publish,archive}.go
Seven HTTP handlers implementing create, update, get, delete, list, publish, and archive flows. Each resolves namespace, maps API ↔ domain inputs, calls h.service.*, checks nil results, and encodes HTTP responses (201/200/204 where applicable).
Handler interface & ctor
api/v3/handlers/addons/handler.go
Introduces Handler interface and internal handler struct plus New(...) constructor to wire namespace resolver, addon.Service, and transport options.
Domain ↔ API conversion
api/v3/handlers/addons/convert.go
Large conversion module handling labels/metadata, status & instance enums, validation error mapping, and extensive billing/rate‑card ↔ API transformations (flat, unit, graduated/volume tiers, tax, discounts, payment terms). Bidirectional converters with detailed error handling for enums and decimals.
Server routing & wiring
api/v3/server/routes.go, api/v3/server/server.go, openmeter/server/server.go
Wires AddonService into v3 server config; constructs addonHandler in server init; routes addon endpoints to the new handler instead of unimplemented stubs; adds config validation for the addon service.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant V3Server as "v3 Server"
  participant Handler as "addons.Handler"
  participant Service as "addon.Service"
  participant Repo as "Repository/ProductCatalog"

  Client->>V3Server: HTTP request (e.g., POST /addons)
  V3Server->>Handler: invoke CreateAddon (resolve namespace, parse body)
  Handler->>Service: CreateAddon(ctx, domainInput)
  Service->>Repo: persist / validate / rate-card logic
  Repo-->>Service: domain addon result
  Service-->>Handler: addon pointer
  Handler-->>V3Server: API addon payload (ToAPIAddon)
  V3Server-->>Client: HTTP 201 JSON response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • refactor: labels support #4118: label conversion helpers and refactor that are directly consumed by the new label ↔ metadata conversion functions in the addons conversion module.

Suggested labels

area/api

Suggested reviewers

  • tothandras
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(api): add-ons v3' clearly summarizes the main change—introducing v3 API support for add-ons, matching the comprehensive handler implementations, conversion utilities, and server integration shown throughout the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feat/addons-v3

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 and usage tips.

@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: 3

🧹 Nitpick comments (3)
api/v3/server/server.go (1)

192-197: Move the AddonService required-check up with the other always-required services

AddonService is unconditionally required (it's not gated on Credits.Enabled), so sticking the nil-check after the if c.Credits.Enabled { ... } block reads a bit oddly — every other always-required service is checked above that block. Hoisting this next to the FeatureConnector check keeps the file's "required first, conditional second" flow intact.

♻️ Small reorder
 	if c.FeatureConnector == nil {
 		errs = append(errs, errors.New("feature connector is required"))
 	}
 
+	if c.AddonService == nil {
+		errs = append(errs, errors.New("addon service is required"))
+	}
+
 	if c.Credits.Enabled {
 		...
 	}
 
-	if c.AddonService == nil {
-		errs = append(errs, errors.New("addon service is required"))
-	}
-
 	return errors.Join(errs...)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/server/server.go` around lines 192 - 197, The AddonService nil-check
should be moved up into the same "always-required" section where
FeatureConnector is validated so the file keeps required services first and
conditional checks (like the c.Credits.Enabled block) after; locate the current
check for AddonService and relocate it immediately after the FeatureConnector
validation (preserving the same error text: errors.New("addon service is
required")), ensuring no behavioral change beyond the reorder.
api/v3/handlers/addons/list.go (1)

57-76: Consider returning service errors unwrapped

Small consistency nit: plans/list.go and friends return the service/convert error directly so the generic error encoder sees the original type. Here the fmt.Errorf("failed to list add-ons: %w", err) / "failed to convert add-on: %w" wrapping still unwraps fine, but it adds a prefix that clients will see in the final message. Either is valid — just flagging for consistency across the v3 handlers.

♻️ Suggested tweak
-		resp, err := h.service.ListAddons(ctx, request)
-			if err != nil {
-				return ListAddonsResponse{}, fmt.Errorf("failed to list add-ons: %w", err)
-			}
+		resp, err := h.service.ListAddons(ctx, request)
+			if err != nil {
+				return ListAddonsResponse{}, err
+			}
 
 			items := make([]apiv3.Addon, 0, len(resp.Items))
 			for _, a := range resp.Items {
-				apiAddon, err := ToAPIAddon(a)
-				if err != nil {
-					return ListAddonsResponse{}, fmt.Errorf("failed to convert add-on: %w", err)
-				}
+				apiAddon, err := ToAPIAddon(a)
+				if err != nil {
+					return ListAddonsResponse{}, err
+				}
 				items = append(items, apiAddon)
 			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/handlers/addons/list.go` around lines 57 - 76, The handler currently
wraps service and conversion errors with fmt.Errorf in the anonymous ListAddons
handler; instead return the original errors from h.service.ListAddons and
ToAPIAddon directly so the generic error encoder sees the original error type
(replace fmt.Errorf("failed to list add-ons: %w", err) and fmt.Errorf("failed to
convert add-on: %w", err) with returning err unchanged when
h.service.ListAddons(ctx, request) or ToAPIAddon(a) fail), leaving the rest of
the function (building items and calling response.NewPagePaginationResponse)
untouched.
api/v3/handlers/addons/create.go (1)

40-40: Add a clarifying comment for IgnoreNonCriticalIssues = true

This hard-coded flag is intentional and follows the same pattern across all create/update handlers for plans and addons. The service layer documents that it allows resources with non-critical validation issues—expected for draft resources. A brief comment here (e.g., // Allow draft addons with non-critical issues, fully validated on publish) would save future readers the archaeology.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/handlers/addons/create.go` at line 40, Add a short inline comment
explaining why IgnoreNonCriticalIssues is set to true in the create handler:
next to the assignment of req.IgnoreNonCriticalIssues = true, add a one-line
comment such as "// Allow draft addons with non-critical validation issues; full
validation occurs on publish" so future readers know this is intentional and
consistent with other create/update handlers (referencing the
req.IgnoreNonCriticalIssues flag in the create addon handler).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@api/v3/handlers/addons/archive.go`:
- Around line 37-47: The current nil-result guard after calling
h.service.ArchiveAddon returns a vague fmt.Errorf("failed to archive add-on");
instead, treat this as an unexpected internal invariant violation and return a
richer error: log or wrap the condition with contextual details (e.g., include
request.AddonID and request.Namespace or other identifying fields from
ArchiveAddonRequest) and return a clear internal error (e.g., errors.New or an
internal-server-error wrapper) so callers get traceable diagnostics; apply the
same change pattern to the analogous check in create.go (the nil check after
h.service.CreateAddon) using the CreateAddonRequest identifiers and the
corresponding service call names to locate the code.

In `@api/v3/handlers/addons/convert.go`:
- Around line 430-437: Change both ToAPIBillingPricePaymentTerm and
FromAPIBillingPriceFlat to explicitly handle only known enum values and return
an error for any unrecognized value instead of silently defaulting; update
ToAPIBillingPricePaymentTerm to return (*apiv3.BillingPricePaymentTerm, error)
and map productcatalog.InArrearsPaymentTerm to
apiv3.BillingPricePaymentTermInArrears and productcatalog.InAdvancePaymentTerm
(or whichever explicit enum represents advance) to
apiv3.BillingPricePaymentTermInAdvance, returning fmt.Errorf("unknown payment
term: %v", t) for anything else; similarly update FromAPIBillingPriceFlat to
validate paymentTermPtr against apiv3.BillingPricePaymentTermInArrears and
BillingPricePaymentTermInAdvance and return an error for nil/unknown values
instead of returning DefaultPaymentTerm, mirroring the explicit-error behavior
used in ToAPIAddonInstanceType.

In `@api/v3/handlers/addons/get.go`:
- Around line 37-44: The handler dereferences *a without checking for nil after
calling h.service.GetAddon, which can panic if GetAddon returns (nil, nil); add
a nil-check for the returned addon (variable a) before calling ToAPIAddon and
return a descriptive error (e.g., fmt.Errorf("addon not found")) wrapped as the
handler error, and add "fmt" to imports; check the same code path in the
anonymous handler function that currently calls ToAPIAddon(*a) and change it to
return GetAddonResponse{}, fmt.Errorf(...) when a == nil.

---

Nitpick comments:
In `@api/v3/handlers/addons/create.go`:
- Line 40: Add a short inline comment explaining why IgnoreNonCriticalIssues is
set to true in the create handler: next to the assignment of
req.IgnoreNonCriticalIssues = true, add a one-line comment such as "// Allow
draft addons with non-critical validation issues; full validation occurs on
publish" so future readers know this is intentional and consistent with other
create/update handlers (referencing the req.IgnoreNonCriticalIssues flag in the
create addon handler).

In `@api/v3/handlers/addons/list.go`:
- Around line 57-76: The handler currently wraps service and conversion errors
with fmt.Errorf in the anonymous ListAddons handler; instead return the original
errors from h.service.ListAddons and ToAPIAddon directly so the generic error
encoder sees the original error type (replace fmt.Errorf("failed to list
add-ons: %w", err) and fmt.Errorf("failed to convert add-on: %w", err) with
returning err unchanged when h.service.ListAddons(ctx, request) or ToAPIAddon(a)
fail), leaving the rest of the function (building items and calling
response.NewPagePaginationResponse) untouched.

In `@api/v3/server/server.go`:
- Around line 192-197: The AddonService nil-check should be moved up into the
same "always-required" section where FeatureConnector is validated so the file
keeps required services first and conditional checks (like the c.Credits.Enabled
block) after; locate the current check for AddonService and relocate it
immediately after the FeatureConnector validation (preserving the same error
text: errors.New("addon service is required")), ensuring no behavioral change
beyond the reorder.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5fe16f01-fd81-4ed6-8e1b-f988a3e60378

📥 Commits

Reviewing files that changed from the base of the PR and between 476cef5 and 4e03bdf.

📒 Files selected for processing (12)
  • api/v3/handlers/addons/archive.go
  • api/v3/handlers/addons/convert.go
  • api/v3/handlers/addons/create.go
  • api/v3/handlers/addons/delete.go
  • api/v3/handlers/addons/get.go
  • api/v3/handlers/addons/handler.go
  • api/v3/handlers/addons/list.go
  • api/v3/handlers/addons/publish.go
  • api/v3/handlers/addons/update.go
  • api/v3/server/routes.go
  • api/v3/server/server.go
  • openmeter/server/server.go

Comment thread api/v3/handlers/addons/archive.go Resolved
Comment thread api/v3/handlers/addons/convert.go Resolved
Comment thread api/v3/handlers/addons/get.go Resolved
tothandras
tothandras previously approved these changes Apr 20, 2026

@chrisgacsal chrisgacsal left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

LGTM!

@tothandras
tothandras merged commit 3212212 into main Apr 20, 2026
24 of 25 checks passed
@tothandras
tothandras deleted the feat/addons-v3 branch April 20, 2026 11:44

This branch was previously deployed

1 inactive deployment
dev — 784db052 Deployed Apr 20, 2026 by rolosp via Migration Checks #13619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants