Repository navigation
fix(api): add-ons http API - #2598
Conversation
📝 WalkthroughWalkthroughThe 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
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 ✨ 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:
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 (6)
openmeter/server/router/addon.go (1)
31-35: Parameter name standardization looks good, but consider struct field naming consistencyThe change from
addonIdOrKeytoaddonIdin 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 namedIDOrKeyin theGetAddonRequestParamsstruct (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
GetAddonRequestParamsto 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 DefinitionThe new PUT endpoint at
/api/v1/addons/{addonId}is now defined with a clear operation ID (updateAddon), summary, and description. The parameter definition foraddonIdincludes 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 OperationThe PUT endpoint now requires a request body that adheres to the
AddonReplaceUpdateschema. This ensures that update requests are validated against the proper data structure. Just verify that theAddonReplaceUpdateschema is accurately defined elsewhere in the API specification.
314-343: Refine GET Endpoint Description and Parameter ValidationsThe GET endpoint for
/api/v1/addons/{addonId}now includes enhanced parameter validations (withminLength,maxLength, and a union regex pattern) and reintroduces theincludeLatestquery 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 unifiedaddonIdparameter. 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 explicitoperationId, summary, and description. The parameteraddonIdnow 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 theaddonIdparameter with enriched validation rules. The use of a dual regex pattern in thepatternfield allows for both the traditional format and the new identifier format. Additionally, the new optional query parameterincludeLatestprovides clients greater control over the returned data.Note that
x-go-typeis 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
📒 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 implementationThe update to the route definition and parameter name from
addonIdOrKeytoaddonIdin 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
addonIdfor consistency, it still maintains theULIDOrKeytype, 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 namingGood 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 consistencyThis change correctly updates the path parameter from
addonIdOrKeytoaddonIdin 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 requirementsThe change from
addonIdOrKeytoaddonIdin 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 nameThe implementation of
GetAddonin theUnimplementedstruct 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 parameterThe middleware function has been renamed and repurposed from handling the
GetAddonoperation to theDeleteAddonoperation, while maintaining the parameter naming convention of usingaddonId. All references and error handling have been appropriately updated.
10973-10976: GetAddon middleware function updated with consistent parameter namingThe
GetAddonmiddleware function now correctly extracts theaddonIdparameter from the request path and processes the optionalincludeLatestquery parameter. This implementation matches the interface definition change.Also applies to: 10987-10999
15126-15129: Router configuration updated to reflect new parameter namesThe router configuration has been updated to use the new route patterns with
addonIdinstead ofaddonIdOrKey, ensuring consistency between the route definitions and the handler function parameters.
16159-16413: Base64 encoded swagger specification contentThis 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 objectivesThe change from
addonIdOrKeytoaddonIdin theGetAddonmethod 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 nameThe implementation of
DeleteAddonproperly uses theaddonIdparameter when generating the request, maintaining consistency with the interface definition.
9784-9785: GetAddon implementation updated to match signature changeThe implementation of
GetAddoncorrectly passes theaddonIdparameter to the request generator function, ensuring consistency throughout the codebase.
11937-11943: Request generator correctly handles updated parameterThe
NewDeleteAddonRequestfunction properly uses theaddonIdparameter and correctly passes it to the path parameter styling function with the matching name.
11971-11972: New request generator function maintains parameter consistencyThe
NewGetAddonRequestfunction signature usesaddonIdinstead of the previousaddonIdOrKey, maintaining consistent naming across the API client.
11997-12017: Query parameter handling implemented correctlyThe 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 GETThe request is properly created with the "GET" HTTP method, aligning with RESTful API conventions for resource retrieval.
19177-19178: ClientWithResponses interface updated consistentlyThe
GetAddonWithResponsemethod signature has been updated with the same parameter name change, maintaining consistency across all client interfaces.
19703-19706: Response type updated to include JSON200 fieldThe
GetAddonResponsestruct now includes aJSON200field of type*Addon, which properly maps the successful response to the expected data structure.
23211-23217: DeleteAddonWithResponse implementation matches interfaceThe implementation of
DeleteAddonWithResponsecorrectly uses the updated parameter name and properly calls theParseDeleteAddonResponsefunction.
23220-23226: GetAddonWithResponse implementation matches interfaceThe implementation of
GetAddonWithResponsecorrectly uses the updated parameter name and properly calls theParseGetAddonResponsefunction.
24768-24779: Response parsing function handles DeleteAddon responsesThe
ParseDeleteAddonResponsefunction correctly constructs the response object with the appropriate fields.
24843-24862: Response parsing function properly handles GetAddon success caseThe
ParseGetAddonResponsefunction correctly handles the 200 status code by unmarshaling the JSON response into anAddonstruct and setting theJSON200field.
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 goLength 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 bothapi/client/go/client.gen.go(lines 9291–9302) and the related changes at lines 19171–19182.
Overview
Refactor GET endpoint of add-ons HTTP API as using
addonIDOrKeywhile otehr operations useaddonIDbreaks the OpenAPI middleware responsible for validating requests.Summary by CodeRabbit
New Features
Refactor