Skip to content

fix(api): add-ons http API - #2598

Merged
chrisgacsal merged 1 commit into
mainfrom
fix/get-addon-api
Apr 4, 2025
Merged

chrisgacsal merged 1 commit into
mainfrom
fix/get-addon-api

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Apr 4, 2025 •

Copy link
Copy Markdown
Collaborator

Overview

Refactor GET endpoint of add-ons HTTP API as using addonIDOrKey while otehr operations use addonID breaks the OpenAPI middleware responsible for validating requests.

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated update endpoint for add-ons that requires a structured payload and supports an optional query parameter for including the latest version.
  • Refactor

    • Standardized the add-on identifier across endpoints to exclusively use "addonId".
    • Updated routing for retrieval and deletion operations and aligned client libraries and API specifications for consistent behavior and improved error handling.

@chrisgacsal chrisgacsal added release-note/bug-fix Release note: Bug Fixes release-note/ignore Ignore this change when generating release notes labels Apr 4, 2025
@chrisgacsal chrisgacsal self-assigned this Apr 4, 2025
@chrisgacsal
chrisgacsal requested a review from a team as a code owner April 4, 2025 21:25
@coderabbitai

coderabbitai Bot commented Apr 4, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes update API parameter names and method signatures to use a single identifier ("addonId") rather than the dual-purpose "addonIdOrKey." Both server and client implementations have been modified accordingly, with adjustments to middleware routing and response parsing functions. In addition, the API specifications (OpenAPI and schema files) have been revised to reflect these new parameters and to restructure the available HTTP methods (including a new PUT for updates and swapped GET/DELETE operations). The route definitions in the product catalog have also been updated for consistency.

Changes

File(s) Change Summary
api/api.gen.go
openmeter/.../addon.go
Updated the GetAddon method signature by replacing addonIdOrKey with addonId. Also, adjusted middleware and routing responsibilities by swapping the GET and DELETE operations.
api/client/go/client.gen.go Renamed parameters in the GetAddon and DeleteAddon methods from addonIdOrKey to addonId and swapped the response types and parsing functions for the corresponding operations.
api/client/javascript/.../schemas.ts Changed the endpoint parameter from addonIdOrKey to addonId and removed definitions for HTTP methods other than GET, updating the operations interface accordingly.
api/openapi.cloud.yaml
api/openapi.yaml
Modified endpoints to replace /api/v1/addons/{addonIdOrKey} with /api/v1/addons/{addonId}. Added a PUT method for updating add-ons with a required request body and reintroduced GET with updated parameters and query requirements.
api/spec/.../routes.tsp Updated the route parameter in the Addons interface from addonIdOrKey to addonId in both the route definition and the method signature.

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

✨ 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.
    • 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 plan to trigger planning for file edits and PR creation.
  • @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.

@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 (6)
openmeter/server/router/addon.go (1)

31-35: Parameter name standardization looks good, but consider struct field naming consistency

The change from addonIdOrKey to addonId in the function signature and route comment aligns with the PR objective of standardizing parameter names across the API for OpenAPI middleware compatibility. This is a good improvement for consistency.

However, I notice that while the parameter name has been updated to addonId, it's still being mapped to a struct field named IDOrKey in the GetAddonRequestParams struct (line 34). This naming inconsistency between the API parameter and internal struct field could potentially cause confusion for future maintainers.

Consider aligning the struct field name in GetAddonRequestParams to match the parameter name or adding a code comment explaining the intentional difference. For example:

a.addonHandler.GetAddon().With(addonhttpdriver.GetAddonRequestParams{
-	IDOrKey:       addonId,
+	IDOrKey:       addonId, // Maps API parameter 'addonId' to internal field that accepts either ID or key
	IncludeLatest: lo.FromPtrOr(params.IncludeLatest, false),
}).ServeHTTP(w, r)
api/openapi.cloud.yaml (3)

237-252: Ensure Consistency in the Update Endpoint Definition

The new PUT endpoint at /api/v1/addons/{addonId} is now defined with a clear operation ID (updateAddon), summary, and description. The parameter definition for addonId includes a strict regex pattern and an example value. This change promotes consistency by replacing the legacy dual-purpose identifier.


307-313: Addition of Request Body for Update Operation

The PUT endpoint now requires a request body that adheres to the AddonReplaceUpdate schema. This ensures that update requests are validated against the proper data structure. Just verify that the AddonReplaceUpdate schema is accurately defined elsewhere in the API specification.


314-343: Refine GET Endpoint Description and Parameter Validations

The GET endpoint for /api/v1/addons/{addonId} now includes enhanced parameter validations (with minLength, maxLength, and a union regex pattern) and reintroduces the includeLatest query parameter. One point to note: the description still states "Get add-on by id or key," which may be misleading given the move to a unified addonId parameter. It would be clearer to update the description to reflect that only the add-on ID is accepted.

api/openapi.yaml (2)

236-248: PUT Endpoint: Consistent Identifier Pattern for Update
The new PUT operation for updating an add-on at /api/v1/addons/{addonId} is clearly defined with an explicit operationId, summary, and description. The parameter addonId now uses a stringent regex pattern (^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$) and includes a concrete example, which is great for enforcing valid IDs.

Please verify that this pattern is fully aligned with the identifier format used elsewhere in your system and documented accordingly for consistency and clarity.


313-337: GET Operation: Flexible Retrieval with Enhanced Validation
The GET method on /api/v1/addons/{addonId} is updated to use the addonId parameter with enriched validation rules. The use of a dual regex pattern in the pattern field allows for both the traditional format and the new identifier format. Additionally, the new optional query parameter includeLatest provides clients greater control over the returned data.

Note that x-go-type is declared both inside the schema and again at the parameter level — please confirm if both declarations are necessary for your code generation tools or if one can be removed to avoid redundancy.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f724cf and 7e389e2.

📒 Files selected for processing (7)
  • api/api.gen.go (7 hunks)
  • api/client/go/client.gen.go (14 hunks)
  • api/client/javascript/src/client/schemas.ts (2 hunks)
  • api/openapi.cloud.yaml (2 hunks)
  • api/openapi.yaml (2 hunks)
  • api/spec/src/productcatalog/routes.tsp (1 hunks)
  • openmeter/server/router/addon.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
openmeter/server/router/addon.go (4)
openmeter/server/router/router.go (1)
  • Router (179-200)
api/api.gen.go (1)
  • GetAddonParams (6209-6214)
api/client/go/client.gen.go (1)
  • GetAddonParams (5830-5835)
openmeter/productcatalog/addon/httpdriver/addon.go (1)
  • GetAddonRequestParams (234-245)
api/api.gen.go (1)
api/client/go/client.gen.go (1)
  • GetAddonParams (5830-5835)
api/client/go/client.gen.go (4)
api/api.gen.go (2)
  • GetAddonParams (6209-6214)
  • Addon (761-813)
openmeter/ent/db/client.go (1)
  • Client (59-135)
api/client/javascript/src/client/schemas.ts (1)
  • Addon (8820-8820)
openmeter/ent/db/predicate/predicate.go (1)
  • Addon (10-10)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Test
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: CI
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (23)
api/spec/src/productcatalog/routes.tsp (1)

250-257: API specification route change aligns with implementation

The update to the route definition and parameter name from addonIdOrKey to addonId in the TypeSpec definition is consistent with the server implementation changes, maintaining alignment between the API specification and implementation.

I appreciate that while the parameter name has been standardized to addonId for consistency, it still maintains the ULIDOrKey type, preserving the functionality of accepting either an ID or a key value.

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

26-26: Consistent endpoint parameter naming

Good change - renaming the path from {addonIdOrKey} to {addonId} aligns this endpoint with the PR's goal of ensuring consistent parameter naming across the API. This will fix the OpenAPI middleware validation issues mentioned in the PR description.


9663-9663: Path parameter updated for consistency

This change correctly updates the path parameter from addonIdOrKey to addonId in the operations interface, maintaining consistency with the endpoint definition. This makes the API more consistent and easier to understand.

api/api.gen.go (6)

9776-9778: Parameter naming change aligns with OpenAPI middleware requirements

The change from addonIdOrKey to addonId in the method signature creates consistency across API endpoints, which will resolve the validation issues with the OpenAPI middleware mentioned in the PR objective.


10142-10146: Unimplemented struct updated to match new parameter name

The implementation of GetAddon in the Unimplemented struct has been correctly updated to match the changed interface definition, maintaining consistency throughout the codebase.


10948-10964: Function renamed from GetAddon to DeleteAddon with updated parameter

The middleware function has been renamed and repurposed from handling the GetAddon operation to the DeleteAddon operation, while maintaining the parameter naming convention of using addonId. All references and error handling have been appropriately updated.


10973-10976: GetAddon middleware function updated with consistent parameter naming

The GetAddon middleware function now correctly extracts the addonId parameter from the request path and processes the optional includeLatest query parameter. This implementation matches the interface definition change.

Also applies to: 10987-10999


15126-15129: Router configuration updated to reflect new parameter names

The router configuration has been updated to use the new route patterns with addonId instead of addonIdOrKey, ensuring consistency between the route definitions and the handler function parameters.


16159-16413: Base64 encoded swagger specification content

This appears to be base64 encoded content of the embedded swagger specification. While this has changed (likely due to the API parameter updates), the encoding itself doesn't require review as it's generated content.

api/client/go/client.gen.go (14)

9297-9298: Parameter name change aligns with PR objectives

The change from addonIdOrKey to addonId in the GetAddon method signature makes the parameter naming consistent with other operations, addressing the original issue described in the PR objectives.


9772-9773: Implementation correctly uses the updated parameter name

The implementation of DeleteAddon properly uses the addonId parameter when generating the request, maintaining consistency with the interface definition.


9784-9785: GetAddon implementation updated to match signature change

The implementation of GetAddon correctly passes the addonId parameter to the request generator function, ensuring consistency throughout the codebase.


11937-11943: Request generator correctly handles updated parameter

The NewDeleteAddonRequest function properly uses the addonId parameter and correctly passes it to the path parameter styling function with the matching name.


11971-11972: New request generator function maintains parameter consistency

The NewGetAddonRequest function signature uses addonId instead of the previous addonIdOrKey, maintaining consistent naming across the API client.


11997-12017: Query parameter handling implemented correctly

The implementation properly handles optional query parameters (like includeLatest) for the GET request, ensuring the client can pass these parameters when needed.


12019-12019: HTTP method correctly set to GET

The request is properly created with the "GET" HTTP method, aligning with RESTful API conventions for resource retrieval.


19177-19178: ClientWithResponses interface updated consistently

The GetAddonWithResponse method signature has been updated with the same parameter name change, maintaining consistency across all client interfaces.


19703-19706: Response type updated to include JSON200 field

The GetAddonResponse struct now includes a JSON200 field of type *Addon, which properly maps the successful response to the expected data structure.


23211-23217: DeleteAddonWithResponse implementation matches interface

The implementation of DeleteAddonWithResponse correctly uses the updated parameter name and properly calls the ParseDeleteAddonResponse function.


23220-23226: GetAddonWithResponse implementation matches interface

The implementation of GetAddonWithResponse correctly uses the updated parameter name and properly calls the ParseGetAddonResponse function.


24768-24779: Response parsing function handles DeleteAddon responses

The ParseDeleteAddonResponse function correctly constructs the response object with the appropriate fields.


24843-24862: Response parsing function properly handles GetAddon success case

The ParseGetAddonResponse function correctly handles the 200 status code by unmarshaling the JSON response into an Addon struct and setting the JSON200 field.


9291-9302:

Details

❓ Verification inconclusive

Verify client usage in the codebase

All interface and implementation changes look correct. As a follow-up, it would be good to verify that all client code using these methods has been updated to use the new parameter name.

Also applies to: 19171-19182


🏁 Script executed:

#!/bin/bash
# Look for any remaining usages of addonIdOrKey in the codebase
echo "Searching for any remaining references to addonIdOrKey..."
rg "addonIdOrKey" --type go

Length of output: 152


Client Parameter Update Verification – Please Manually Confirm

The initial search for "addonIdOrKey" returned no results in Go files, suggesting that references to the old parameter name may have been successfully removed. However, since the automated search produced no output (which might be due to search configuration or context limitations), please perform a manual or broader search (e.g., across all file types) to ensure no lingering usages remain. This verification is particularly important for the client code changes in both api/client/go/client.gen.go (lines 9291–9302) and the related changes at lines 19171–19182.

Comment thread api/openapi.yaml Resolved
@chrisgacsal
chrisgacsal merged commit 9667ec3 into main Apr 4, 2025
@chrisgacsal
chrisgacsal deleted the fix/get-addon-api branch April 4, 2025 21:36
@coderabbitai coderabbitai Bot mentioned this pull request Apr 7, 2025
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 release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants