Skip to content

feat: enable planaddon HTTP API - #2684

Merged
chrisgacsal merged 5 commits into
mainfrom
feat/productcatalog
Apr 16, 2025
Merged

chrisgacsal merged 5 commits into
mainfrom
feat/productcatalog

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Apr 16, 2025 •

Copy link
Copy Markdown
Collaborator

Overview

  • implement HTTP API for plan add-on assignement service
  • enable HTTP API for plan add-on assignement service

Summary by CodeRabbit

  • New Features

    • Introduced full support for managing plan add-ons, including listing, creating, updating, deleting, and retrieving plan add-ons via the API and user interface.
    • Added advanced filtering, sorting, and pagination options when listing plan add-ons.
    • Plan add-ons now include system-managed annotations, visible as read-only metadata.
  • Enhancements

    • API responses for plan add-on listings now provide paginated results with total count and page information.
    • Improved error handling and response formatting for plan add-on operations.

@chrisgacsal chrisgacsal added the release-note/feature Release note: Exciting New Features label Apr 16, 2025
@chrisgacsal chrisgacsal self-assigned this Apr 16, 2025
@chrisgacsal
chrisgacsal requested a review from a team as a code owner April 16, 2025 21:02
@coderabbitai

coderabbitai Bot commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This change introduces full API, HTTP handler, router, and service integration for managing plan add-ons within the product catalog. It adds support for listing, creating, updating, deleting, and retrieving plan add-ons, with enhanced capabilities for filtering, ordering, and pagination. The API schemas and OpenAPI specifications are updated to reflect these features, including a new paginated response type and a read-only annotations property on plan add-ons. The Go server is wired to include the new plan add-on service, and new HTTP driver files implement the request handling and mapping logic. The router is updated to delegate plan add-on endpoints to these handlers.

Changes

Files/Paths Change Summary
api/client/javascript/src/client/schemas.ts
api/openapi.cloud.yaml
api/openapi.yaml
Extended the PlanAddon schema with an optional, read-only annotations property; introduced new enum/type for ordering (PlanAddonOrderBy); added paginated response type (PlanAddonPaginatedResponse); expanded list endpoint query parameters for filtering, ordering, and pagination; changed list endpoint response from array to paginated response.
api/spec/src/productcatalog/planaddon.tsp Added annotations property to PlanAddon model and introduced PlanAddonOrderBy enum for ordering options.
api/spec/src/productcatalog/routes.tsp Updated PlanAddons interface: changed list method to return a paginated response and accept new query parameters for filtering, pagination, and ordering.
app/common/productcatalog.go Added PlanAddon service initialization and provider wiring, including a new constructor function for the plan add-on service.
cmd/server/main.go Passed the PlanAddon service into the router configuration for server initialization.
cmd/server/wire.go
cmd/server/wire_gen.go
Added PlanAddon field to the Application struct; initialized and injected the plan add-on service during application setup.
openmeter/productcatalog/planaddon/httpdriver/driver.go
errors.go
mapping.go
planaddon.go
Introduced new HTTP driver package for plan add-ons: defined interfaces and handler struct; implemented error encoding; added mapping functions between domain and API models; implemented HTTP handlers for listing, creating, updating, deleting, and retrieving plan add-ons, including request parsing, service calls, response formatting, and error handling.
openmeter/server/router/planaddon.go Fully implemented router methods for plan add-on endpoints, delegating to the new HTTP handlers and updating method signatures to accept new query parameters.
openmeter/server/router/router.go Added the plan add-on service and handler to the router configuration, validation, and construction logic.
openmeter/server/server_test.go Added a no-op PlanAddon service implementation for testing and integrated it into the test server setup.

Possibly related PRs

  • openmeterio/openmeter#2661: Implements the initial plan add-ons API endpoints and schemas; this PR directly extends those endpoints with pagination, filtering, ordering, and annotations.
  • openmeterio/openmeter#2681: Implements the core service logic for plan add-ons, which this PR utilizes and exposes via API, HTTP handlers, and routing.
  • openmeterio/openmeter#2662: Extends the existing plan add-on API client with pagination, filtering, ordering, and annotations, complementing the API-level changes in this PR.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3194bb5 and 0729e0f.

📒 Files selected for processing (1)
  • openmeter/server/server_test.go (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
openmeter/server/server_test.go (2)
api/api.gen.go (2)
  • Plan (4876-4927)
  • PlanAddon (4930-4964)
openmeter/productcatalog/planaddon/service.go (5)
  • ListPlanAddonsInput (41-80)
  • CreatePlanAddonInput (88-108)
  • DeletePlanAddonInput (245-253)
  • GetPlanAddonInput (212-223)
  • UpdatePlanAddonInput (133-156)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Quickstart
  • GitHub Check: E2E
  • GitHub Check: CI
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: Test
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (4)
openmeter/server/server_test.go (4)

47-47: Import added correctly for the plan addon module.

The import statement for the planaddon package is properly added to support the new plan addon service functionality in the tests.


473-473: Good initialization of plan addon no-op service.

The planAddonService variable is initialized with a no-op implementation following the same pattern as other services in the test setup.


512-513: Proper integration of plan addon service into router config.

The PlanAddon field is correctly added to the router configuration, allowing the HTTP handlers to access the no-op service during tests.


1123-1147: Well-implemented no-op service for plan addons.

The NoopPlanAddonService implementation follows the established patterns in the codebase:

  1. Interface compliance is verified with the type assertion
  2. All required methods are implemented with appropriate no-op functionality
  3. Documentation matches the style of other no-op services

This provides a clean test double for the plan addon service without requiring external dependencies.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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 changed the title feat: enable planaddon http api feat: enable planaddon HTTP API]\ Apr 16, 2025
@chrisgacsal chrisgacsal changed the title feat: enable planaddon HTTP API]\ feat: enable planaddon HTTP API Apr 16, 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: 5

🧹 Nitpick comments (11)
api/spec/src/productcatalog/planaddon.tsp (1)

21-28: Document the plan for metadata field implementation.

The commented-out metadata field has a FIXME note, but no additional context on when or how it will be implemented.

Consider adding a more detailed comment explaining:

  1. The reason for disabling this field currently
  2. The conditions needed to enable it
  3. Any tracking issue number for reference
app/common/productcatalog.go (1)

104-126: Fix inconsistent naming in logger and error message.

There are two minor inconsistencies in the service initialization:

  1. The error message refers to "add-on adapter" but should be "plan add-on adapter" for clarity.
  2. The logger subsystem is set to "productcatalog.addon" but should be "productcatalog.planaddon" to be consistent with the adapter initialization.
 	if err != nil {
-		return nil, fmt.Errorf("failed to initialize add-on adapter: %w", err)
+		return nil, fmt.Errorf("failed to initialize plan add-on adapter: %w", err)
 	}

 	return planaddonservice.New(planaddonservice.Config{
 		Adapter:   adapter,
 		Plan:      planService,
 		Addon:     addonService,
-		Logger:    logger.With("subsystem", "productcatalog.addon"),
+		Logger:    logger.With("subsystem", "productcatalog.planaddon"),
 		Publisher: publisher,
 	})
openmeter/productcatalog/planaddon/httpdriver/driver.go (1)

34-38: Consider using a more specific error message.

The current error message is generic ("internal server error") and doesn't indicate what actually went wrong. A more descriptive message would help with debugging.

-		return "", commonhttp.NewHTTPError(http.StatusInternalServerError, errors.New("internal server error"))
+		return "", commonhttp.NewHTTPError(http.StatusInternalServerError, errors.New("failed to resolve namespace from context"))
api/openapi.yaml (1)

6889-6949: Ensure explicit explode setting for array query parameters
The id and key parameters are defined as arrays with style: form but lack an explicit explode: false. Depending on the server/client defaults, this could change how CSV values are parsed vs. repeated parameters. To avoid ambiguity, add explode: false to both parameters.

Proposed diff:

         - name: id
           in: query
           required: false
           description: Filter by addon.id attribute.
           schema:
             type: array
             items:
               type: string
               pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
               description: ULID (Universally Unique Lexicographically Sortable Identifier).
               example: 01G65Z755AFWAKHE12NY0CQ9FH
-          style: form
+          style: form
+          explode: false

         - name: key
           in: query
           required: false
           description: Filter by addon.key attribute.
           schema:
             type: array
             items:
               type: string
               minLength: 1
               maxLength: 64
               pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
               description: A key is a unique string that is used to identify a resource.
-          style: form
+          style: form
+          explode: false
api/openapi.cloud.yaml (3)

6891-6942: Explicitly specify explode for array query parameters to ensure consistent serialization.

The id and key parameters define style: form but omit explode. By default, form-style arrays use explode=true (e.g., id=A&id=B), whereas explode=false yields comma-separated values (id=A,B). To avoid ambiguity and align with your API client expectations, consider adding:

- name: id
  in: query
  required: false
  description: Filter by addon.id attribute.
  schema:
    type: array
    items:
      type: string
      pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$
      description: ULID...
  style: form
  explode: false

- name: key
  in: query
  required: false
  description: Filter by addon.key attribute.
  schema:
    type: array
    items:
      type: string
      minLength: 1
      maxLength: 64
      pattern: ^[a-z0-9]+(?:_[a-z0-9]+)*$
  style: form
  explode: false

10664-10683: Clarify component parameter naming for ordering.

The parameters live under components/parameters/PlanAddonOrderByOrdering, which combines “OrderBy” and “Ordering” and can be confusing. For better readability, consider renaming the component to something like PlanAddonOrdering (or PlanAddonListOrdering):

- PlanAddonOrderByOrdering.order:
+ PlanAddonOrdering.order:

- PlanAddonOrderByOrdering.orderBy:
+ PlanAddonOrdering.orderBy:

This streamlines the naming and clearly conveys the intent of these query parameters.


17948-17983: Enhance schema documentation with examples and defaults.

  • Add an example to the PlanAddonOrderBy enum for clarity:
    example: created_at
  • Indicate that items in the paginated response may be empty by adding a default:
    items:
      type: array
      items:
        $ref: '#/components/schemas/PlanAddon'
      description: The items in the current page.
      default: []

These tweaks will improve API documentation and help client generators produce more accurate stubs.

api/client/javascript/src/client/schemas.ts (1)

18873-18898: Comprehensive filtering capabilities for the list operation.

The updated listPlanAddons operation now supports a rich set of filtering options including:

  • Inclusion of deleted items
  • Filtering by ID or key
  • Pagination and sorting

The keyVersion parameter has a more complex structure that allows filtering by both key and version. Consider adding a code example in the documentation to illustrate how to use this parameter effectively.

        /** @description Filter by addon.key and addon.version attributes. */
        keyVersion?: {
          [key: string]: number[]
+         // Example: { "basic": [1, 2], "premium": [3] } to filter for basic v1/v2 and premium v3
        }
openmeter/productcatalog/planaddon/httpdriver/planaddon.go (3)

106-110: Limit the JSON request body size to mitigate DoS risk

commonhttp.JSONRequestBodyDecoder reads the entire body; an attacker can send an arbitrarily large payload.
Wrap the body with http.MaxBytesReader (or add a size‑aware decoder) before decoding.

-			body := api.PlanAddonCreate{}
-			if err := commonhttp.JSONRequestBodyDecoder(r, &body); err != nil {
+			const maxBody = 1 << 20 // 1 MiB – adjust as appropriate
+			r.Body = http.MaxBytesReader(nil, r.Body, maxBody)
+
+			var body api.PlanAddonCreate
+			if err := commonhttp.JSONRequestBodyDecoder(r, &body); err != nil {
 				return CreatePlanAddonRequest{}, fmt.Errorf("failed to decode create plan add-on assignment request: %w", err)
 			}

112-116: Minor: error message includes an (unresolved) namespace

When resolveNamespace fails, ns is expected to be empty, so printing it adds no value and slightly clutters logs.
Consider omitting the placeholder or logging the underlying error only.


198-200: Prefer struct{} over interface{} for empty responses

interface{} permits any value and slightly weakens type‑safety.
Using struct{} conveys intent (always empty) and prevents accidental payloads:

-type (
-	DeletePlanAddonResponse = interface{}
+type (
+	DeletePlanAddonResponse = struct{}

(and return struct{}{} instead of nil).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92b94c1 and 66fba09.

📒 Files selected for processing (15)
  • api/client/javascript/src/client/schemas.ts (7 hunks)
  • api/openapi.cloud.yaml (4 hunks)
  • api/openapi.yaml (4 hunks)
  • api/spec/src/productcatalog/planaddon.tsp (2 hunks)
  • api/spec/src/productcatalog/routes.tsp (1 hunks)
  • app/common/productcatalog.go (3 hunks)
  • cmd/server/main.go (1 hunks)
  • cmd/server/wire.go (2 hunks)
  • cmd/server/wire_gen.go (4 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/driver.go (1 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/errors.go (1 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/mapping.go (1 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/planaddon.go (1 hunks)
  • openmeter/server/router/planaddon.go (1 hunks)
  • openmeter/server/router/router.go (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
cmd/server/wire.go (4)
app/common/productcatalog.go (1)
  • PlanAddon (45-47)
openmeter/ent/db/predicate/predicate.go (1)
  • PlanAddon (210-210)
openmeter/productcatalog/addon/service.go (1)
  • Service (35-44)
openmeter/productcatalog/plan/service.go (1)
  • Service (35-44)
cmd/server/main.go (4)
app/common/productcatalog.go (1)
  • PlanAddon (45-47)
api/api.gen.go (1)
  • PlanAddon (4930-4964)
openmeter/ent/db/predicate/predicate.go (1)
  • PlanAddon (210-210)
api/client/go/client.gen.go (1)
  • PlanAddon (4483-4517)
openmeter/productcatalog/planaddon/httpdriver/errors.go (2)
pkg/framework/commonhttp/errors.go (1)
  • HandleErrorIfTypeMatches (62-75)
openmeter/productcatalog/feature/feature.go (1)
  • FeatureNotFoundError (11-13)
openmeter/server/router/planaddon.go (3)
openmeter/server/router/router.go (1)
  • Router (201-224)
api/api.gen.go (1)
  • ListPlanAddonsParams (7363-7393)
openmeter/productcatalog/planaddon/httpdriver/planaddon.go (3)
  • DeletePlanAddonParams (194-197)
  • GetPlanAddonParams (238-241)
  • UpdatePlanAddonParams (145-148)
openmeter/productcatalog/planaddon/httpdriver/driver.go (3)
openmeter/productcatalog/planaddon/httpdriver/planaddon.go (5)
  • ListPlanAddonsHandler (33-33)
  • CreatePlanAddonHandler (101-101)
  • DeletePlanAddonHandler (199-199)
  • GetPlanAddonHandler (243-243)
  • UpdatePlanAddonHandler (150-150)
pkg/framework/transport/httptransport/options.go (1)
  • HandlerOption (19-21)
pkg/framework/commonhttp/errors.go (1)
  • NewHTTPError (35-41)
openmeter/server/router/router.go (2)
openmeter/productcatalog/addon/service/service.go (1)
  • New (19-42)
pkg/framework/transport/httptransport/options.go (1)
  • WithErrorHandler (29-33)
api/client/javascript/src/client/schemas.ts (2)
api/api.gen.go (2)
  • PlanAddonOrderBy (4983-4983)
  • PlanAddonPaginatedResponse (4986-4998)
api/client/go/client.gen.go (2)
  • PlanAddonOrderBy (4536-4536)
  • PlanAddonPaginatedResponse (4539-4551)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: CI
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: Test
  • GitHub Check: Lint
  • GitHub Check: Analyze (go)
🔇 Additional comments (27)
cmd/server/wire.go (2)

32-32: LGTM: Import added for the planaddon package.

This import allows the application to use the planaddon service, which is part of the broader plan add-on assignment HTTP API implementation.


67-67: LGTM: New PlanAddon field added to Application struct.

The PlanAddon service field is correctly added to the Application struct, following the same pattern as other services in the codebase. This allows the service to be properly injected and accessed by the application.

cmd/server/main.go (1)

170-170: LGTM: PlanAddon service correctly wired to router configuration.

The PlanAddon service is correctly added to the RouterConfig struct, following the established pattern for other services. This enables HTTP routes to access the service implementation.

api/spec/src/productcatalog/planaddon.tsp (2)

14-20: LGTM: Added annotations field with appropriate visibility.

The annotations field is properly defined as a read-only property with clear documentation indicating it's managed by the system and cannot be modified by users.


81-91: LGTM: Well-defined PlanAddonOrderBy enum for listing operations.

The PlanAddonOrderBy enum properly defines the available ordering options for plan add-on listings, which will be used for the HTTP API's filtering and sorting capabilities.

openmeter/productcatalog/planaddon/httpdriver/errors.go (1)

12-16:

Details

❌ Incorrect review comment

Verify the error type match is correct for this context.

The error encoder is specifically handling *feature.FeatureNotFoundError in a plan add-on context. Is this the correct error type, or should there be a more specific planaddon.NotFoundError?


🏁 Script executed:

#!/bin/bash
# Check if there are any usage patterns of FeatureNotFoundError in planaddon package
rg -A 3 "FeatureNotFoundError" --glob "openmeter/productcatalog/planaddon/**/*.go"

# Check if plan add-on service uses feature service
rg -A 3 "feature\.(Service|FeatureConnector)" --glob "openmeter/productcatalog/planaddon/**/*.go"

Length of output: 761


Ignore the suggestion to introduce planaddon.NotFoundError.

There is no planaddon.NotFoundError defined in the codebase—only feature.FeatureNotFoundError exists. Handling *feature.FeatureNotFoundError in openmeter/productcatalog/planaddon/httpdriver/errors.go is correct.

  • File needing no change:
    openmeter/productcatalog/planaddon/httpdriver/errors.go

Likely an incorrect or invalid review comment.

cmd/server/wire_gen.go (1)

29-29: Well-integrated service initialization!

The new planaddon service is properly integrated into the application's dependency injection setup. The initialization follows the existing pattern with appropriate error handling and cleanup procedures.

Also applies to: 382-392, 458-458

openmeter/server/router/planaddon.go (4)

11-17: LGTM! ListPlanAddons implementation.

The handler properly maps API parameters to the service's expected format.


21-22: LGTM! CreatePlanAddon implementation.

Simple and correct delegation to the handler.


27-31: LGTM! DeletePlanAddon implementation.

Correctly maps the path parameters to the expected DeletePlanAddonParams structure.


36-40: LGTM! GetPlanAddon implementation.

Proper handling of plan and addon identifiers that might be either IDs or keys.

openmeter/server/router/router.go (1)

48-49: LGTM! Well-integrated router extension.

The plan addon service and handler are properly integrated into the router with appropriate validation and configuration. The pattern is consistent with other services in the router.

Also applies to: 101-101, 174-176, 210-210, 352-356

app/common/productcatalog.go (1)

20-22: LGTM! Clean integration of PlanAddon dependency.

The PlanAddon service is properly added to the dependency injection framework with appropriate imports and wire sets.

Also applies to: 30-30, 45-47

api/spec/src/productcatalog/routes.tsp (1)

178-208: LGTM: Well-structured API endpoint design with comprehensive filtering and pagination.

The changes to the PlanAddons list method correctly implement filtering, pagination, and ordering capabilities consistent with other API endpoints in the codebase. The parameters follow established patterns used in similar interfaces (Plans, Addons) and provide appropriate documentation for each option.

openmeter/productcatalog/planaddon/httpdriver/mapping.go (2)

55-55: Consider using the request's FromPlanPhase value.

In the create request mapping, FromPlanPhase is set to an empty string rather than using the value from the request. This might be intentional, but differs from the update request which preserves the value.

Please verify if FromPlanPhase should be initialized from the request:

-		FromPlanPhase: "",
+		FromPlanPhase: a.FromPlanPhase,

33-45: Good defensive coding to avoid nil pointer dereferences.

The FromAnnotations function correctly handles empty annotations by returning a non-nil pointer to an empty map, which is a good practice to prevent nil pointer dereferences in client code.

openmeter/productcatalog/planaddon/httpdriver/driver.go (2)

14-24: LGTM: Well-designed interface hierarchy for PlanAddon HTTP handlers.

The interface design follows good separation of concerns with a main Handler interface extending the specific PlanAddonHandler interface. The method signatures correspond to standard REST operations and match the handler types defined elsewhere.


43-53: LGTM: Clean constructor with proper dependency injection.

The constructor function takes the required dependencies and optional handler options, following good dependency injection patterns. The handler struct is properly initialized with all necessary components.

api/openapi.yaml (2)

18241-18246: Add annotations property to PlanAddon schema
The addition of the read-only annotations property correctly surfaces system-managed metadata on plan add-ons. The allOf reference to the common Annotations schema and the readOnly: true flag align with the intended design.


18325-18360: Introduce PlanAddonOrderBy enum and Paginated Response schema
The PlanAddonOrderBy enum lists all sortable fields, and PlanAddonPaginatedResponse encapsulates pagination metadata (totalCount, page, pageSize, items). This structured approach aligns well with API best practices for filtering, sorting, and pagination.

api/openapi.cloud.yaml (1)

17864-17870: Verify Annotations schema is defined and correctly modeled.

The new annotations property references #/components/schemas/Annotations. Please confirm that you have defined an Annotations schema (for example, as an object with additionalProperties: { type: string }). If it’s missing, add:

Annotations:
  type: object
  additionalProperties:
    type: string
  description: Map of system-managed key-value annotations.
api/client/javascript/src/client/schemas.ts (4)

7203-7207: LGTM: The new readonly annotations property is well-defined.

The addition of a system-managed, read-only annotations property to the PlanAddon schema is a good practice for extending the model with metadata that should be protected from user modification.


7274-7298: The pagination and ordering structures align with API best practices.

The newly added PlanAddonOrderBy enum and PlanAddonPaginatedResponse type provide essential pagination and sorting capabilities for the plan add-on API. The pagination structure includes all the necessary fields for client-side handling of paginated results.

Note that the enum values use snake_case ('created_at', 'updated_at') rather than camelCase, which is presumably to match the API's query parameter format.


9422-9424: Consistent parameter definitions for ordering.

The parameter definitions and corresponding exported types for ordering plan add-ons are properly defined and will enable strong typing for API consumers.

Also applies to: 10091-10094


18913-18913: Response type updated to match new paginated structure.

The response type has been correctly updated to use the new paginated response structure, which is consistent with the backend API changes.

openmeter/productcatalog/planaddon/httpdriver/planaddon.go (2)

50-55: PlanIDs and PlanKeys are both populated – may unintentionally filter everything out

Both fields are filled with the same PlanIDOrKey value.
If the service layer treats the two filters as an AND (ID and key must match), every request where the caller supplies either an ID or a key—​but not both—​will return an empty list.

Double‑check the semantics in planaddon.Service.ListPlanAddons. If it is indeed an intersection, populate only one of the slices (or make the service treat them as a union).


126-133: Potential nil‑pointer dereference from service.CreatePlanAddon

CreatePlanAddon returns (*planaddon.PlanAddon, error). If it (unexpectedly) returns (nil, nil) you’ll dereference *a and panic.

Either:

if a == nil {
    return CreatePlanAddonResponse{}, errors.New("service returned nil plan add‑on")
}
return FromPlanAddon(*a)

or make the service guarantee a non‑nil result.

Comment thread openmeter/server/router/planaddon.go Resolved
Comment thread api/openapi.yaml Resolved
tothandras
tothandras previously approved these changes Apr 16, 2025
tothandras
tothandras previously approved these changes Apr 16, 2025
tothandras
tothandras previously approved these changes Apr 16, 2025
@chrisgacsal
chrisgacsal enabled auto-merge (squash) April 16, 2025 21:34
@chrisgacsal
chrisgacsal merged commit 3cda6d2 into main Apr 16, 2025
@chrisgacsal
chrisgacsal deleted the feat/productcatalog branch April 16, 2025 21:39
@coderabbitai coderabbitai Bot mentioned this pull request Sep 16, 2025
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.

2 participants