Skip to content

Conversation

@chrisgacsal
Copy link
Collaborator

@chrisgacsal chrisgacsal commented Apr 16, 2025

Overview

Fix plan add-on assignment HTTP API spec:

  • add support for metadata
  • create request body

Summary by CodeRabbit

  • New Features
    • Added support for including optional metadata on plan add-on assignments when creating or updating them via the API.
  • Refactor
    • Renamed the update model for plan add-ons to improve clarity and consistency.
    • Updated API endpoints and schemas to use the new model name and structure.
    • Enhanced internal request handling to support metadata conversion and integration.
  • Documentation
    • Improved schema descriptions and ordering of properties in API documentation for better clarity.

@chrisgacsal chrisgacsal added the release-note/ignore Ignore this change when generating release notes label Apr 16, 2025
@chrisgacsal chrisgacsal requested a review from tothandras April 16, 2025 22:00
@chrisgacsal chrisgacsal self-assigned this Apr 16, 2025
@chrisgacsal chrisgacsal requested a review from a team as a code owner April 16, 2025 22:00
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 16, 2025

📝 Walkthrough

Walkthrough

This change adds an optional metadata field to the plan add-on assignment models across the API, OpenAPI specs, Go and JavaScript clients, and internal mapping logic. The update also renames the PlanAddonUpdate model to PlanAddonReplaceUpdate for both schema and client types, and updates all relevant request/response types and handler signatures to use the new model. The mapping layer is enhanced to convert metadata fields between internal and API representations. OpenAPI specifications and TypeSpec source files are updated to reflect these changes, ensuring consistent support for metadata in plan add-on assignment creation and update operations.

Changes

Files/Paths Change Summary
api/api.gen.go, api/client/go/client.gen.go Added optional Metadata field to PlanAddon, PlanAddonCreate, and PlanAddonReplaceUpdate; renamed update model; updated type alias for update requests; updated swagger spec.
api/client/javascript/src/client/schemas.ts Added optional metadata field to interfaces; renamed PlanAddonUpdate to PlanAddonReplaceUpdate; updated API operation to use new schema.
api/openapi.cloud.yaml, api/openapi.yaml Added metadata property to PlanAddon and PlanAddonCreate schemas; replaced PlanAddonUpdate with PlanAddonReplaceUpdate in update endpoint; introduced new update schema.
api/spec/src/productcatalog/planaddon.tsp Enabled and annotated metadata property in PlanAddon; added PlanAddonCreate model with proper lifecycle visibility and property inheritance.
api/spec/src/productcatalog/routes.tsp Changed create and update method signatures to use new request body types (PlanAddonCreate, ResourceReplaceModel<PlanAddon>).
openmeter/productcatalog/planaddon/httpdriver/mapping.go Added conversion functions for Metadata; integrated Metadata mapping in create/update request builders; updated function signatures.
openmeter/productcatalog/planaddon/httpdriver/planaddon.go Updated handler to use PlanAddonReplaceUpdate for decoding update requests.

Possibly related PRs

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 fe68fce and 965ee72.

📒 Files selected for processing (9)
  • api/api.gen.go (5 hunks)
  • api/client/go/client.gen.go (5 hunks)
  • api/client/javascript/src/client/schemas.ts (6 hunks)
  • api/openapi.cloud.yaml (5 hunks)
  • api/openapi.yaml (5 hunks)
  • api/spec/src/productcatalog/planaddon.tsp (2 hunks)
  • api/spec/src/productcatalog/routes.tsp (2 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/mapping.go (4 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/planaddon.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (9)
  • openmeter/productcatalog/planaddon/httpdriver/planaddon.go
  • api/spec/src/productcatalog/planaddon.tsp
  • api/spec/src/productcatalog/routes.tsp
  • openmeter/productcatalog/planaddon/httpdriver/mapping.go
  • api/client/go/client.gen.go
  • api/openapi.cloud.yaml
  • api/client/javascript/src/client/schemas.ts
  • api/openapi.yaml
  • api/api.gen.go
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Quickstart
  • GitHub Check: Test
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Developer environment
  • GitHub Check: CI
  • GitHub Check: Build
  • GitHub Check: Commit hooks
  • GitHub Check: Analyze (go)

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

tothandras
tothandras previously approved these changes Apr 16, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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

17954-17956: Enhance descriptions for clarity
The new descriptions on the addon property and the overall PlanAddonCreate schema improve discoverability. Please verify the indentation under properties remains consistent with other component definitions.

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

7271-7281: Improve field order for better readability.

The required addon field has been moved after the optional metadata field. While this doesn't affect functionality, it's generally a good practice to place required fields before optional ones for better developer experience.

  PlanAddonCreate: {
    /**
+     * Addon
+     * @description The add-on to create.
+     */
+    addon: {
+      /**
+       * @description The ID of the add-on.
+       * @example 01G65Z755AFWAKHE12NY0CQ9FH
+       */
+      id: string
+    }
+    /**
     * Metadata
     * @description Additional metadata for the resource.
     */
    metadata?: components['schemas']['Metadata']
-    /**
-     * Addon
-     * @description The add-on to create.
-     */
-    addon: {
-      /**
-       * @description The ID of the add-on.
-       * @example 01G65Z755AFWAKHE12NY0CQ9FH
-       */
-      id: string
-    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3cda6d2 and fe68fce.

📒 Files selected for processing (9)
  • api/api.gen.go (5 hunks)
  • api/client/go/client.gen.go (5 hunks)
  • api/client/javascript/src/client/schemas.ts (6 hunks)
  • api/openapi.cloud.yaml (5 hunks)
  • api/openapi.yaml (5 hunks)
  • api/spec/src/productcatalog/planaddon.tsp (2 hunks)
  • api/spec/src/productcatalog/routes.tsp (2 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/mapping.go (4 hunks)
  • openmeter/productcatalog/planaddon/httpdriver/planaddon.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
openmeter/productcatalog/planaddon/httpdriver/planaddon.go (3)
api/client/javascript/src/client/schemas.ts (1)
  • PlanAddonReplaceUpdate (9855-9856)
api/api.gen.go (1)
  • PlanAddonReplaceUpdate (5007-5017)
api/client/go/client.gen.go (1)
  • PlanAddonReplaceUpdate (4560-4570)
api/client/go/client.gen.go (3)
api/api.gen.go (2)
  • Metadata (4277-4277)
  • PlanAddonReplaceUpdate (5007-5017)
openmeter/billing/profile.go (1)
  • Metadata (22-22)
openmeter/productcatalog/plan/httpdriver/mapping.go (1)
  • FromPlanPhase (65-85)
api/api.gen.go (4)
api/client/go/client.gen.go (2)
  • Metadata (3873-3873)
  • PlanAddonReplaceUpdate (4560-4570)
openmeter/billing/profile.go (1)
  • Metadata (22-22)
openmeter/productcatalog/plan/httpdriver/mapping.go (1)
  • FromPlanPhase (65-85)
openmeter/ent/db/planaddon/where.go (1)
  • MaxQuantity (104-106)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Quickstart
  • GitHub Check: E2E
  • GitHub Check: Developer environment
  • GitHub Check: CI
  • GitHub Check: Lint
  • GitHub Check: Commit hooks
  • GitHub Check: Test
  • GitHub Check: Build
  • GitHub Check: Analyze (go)
🔇 Additional comments (36)
openmeter/productcatalog/planaddon/httpdriver/planaddon.go (1)

156-156: Update handler to match renamed request type.

The change from api.PlanAddonUpdate to api.PlanAddonReplaceUpdate aligns with the renamed model in the API specifications and client libraries. This update properly handles the new model that includes an optional Metadata field.

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

21-26: Good addition of metadata support.

Adding the metadata field to the PlanAddon model with appropriate visibility annotations for read, create, and update operations is well-structured. This matches the PR objective of supporting metadata in plan add-on assignments.


92-114: Well-structured model for create operations.

The new PlanAddonCreate model correctly inherits properties from PlanAddon while customizing the addon property to only include the ID field. This specialization provides better type safety for create operations.

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

219-219: Improved type safety for create operation.

Changing from a generic ResourceCreateModel<PlanAddon> to the more specific PlanAddonCreate model improves type safety and provides better documentation of the expected request structure.


240-240: Updated update operation to use proper resource model.

Switching to TypeSpec.Rest.Resource.ResourceReplaceModel<PlanAddon> correctly aligns with the renamed and restructured update model. This change ensures consistent handling of metadata fields in update operations.

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

4512-4517: Good addition of metadata field to the PlanAddon struct

Adding the optional metadata field to the plan add-on model aligns with the PR objective of enhancing the API spec for plan add-on assignments.


4522-4539: Good improvement to struct documentation and metadata field addition

The updated comment clarifies this is a "plan add-on assignment create request" and the metadata field is added consistently with the same pattern used elsewhere in the codebase.


4559-4570: Appropriate model rename and metadata field addition

Renaming from PlanAddonUpdate to PlanAddonReplaceUpdate better reflects that this is a replace operation. The updated comment and metadata field addition match the PR's stated purpose.


7131-7131: Correctly updated type alias for the renamed struct

The type alias UpdatePlanAddonJSONRequestBody now references the renamed PlanAddonReplaceUpdate struct, maintaining consistency throughout the API.


37035-37053: Updated encoded OpenAPI specification

This change updates the encoded OpenAPI specification that's embedded in the generated client code to reflect the model changes.

api/api.gen.go (6)

4962-4963: Addition of Metadata field to PlanAddon struct

The addition of the Metadata field to the PlanAddon struct aligns with the PR objective of adding metadata support to plan add-on assignments. The field is properly defined as an optional pointer to the Metadata type.


4984-4985: Addition of Metadata field to PlanAddonCreate struct

Good addition of the Metadata field to the creation request model, maintaining consistency across the API. This ensures metadata can be specified when creating plan add-on assignments.


5006-5007: Renamed PlanAddonUpdate to PlanAddonReplaceUpdate with Metadata field

The struct has been appropriately renamed from PlanAddonUpdate to PlanAddonReplaceUpdate to better reflect its purpose, and the Metadata field has been added, consistent with other model changes.

Also applies to: 5015-5016


7640-7641: Updated RequestBody type to use renamed struct

The type alias for the update request body has been properly updated to use the renamed struct PlanAddonReplaceUpdate.


16869-17091: Updated embedded Swagger specification

The embedded Swagger specification has been updated to reflect the model changes, including the addition of the metadata field and the renaming of the update model.


17092-17424:

Details

❓ Verification inconclusive

Verify impact of changes on existing clients

As these changes modify the API contract by renaming types and adding new fields, ensure that existing clients are updated or can handle these changes gracefully.

Run the following script to check for any direct usage of the old type name:


🏁 Script executed:

#!/bin/bash
# Search for any references to PlanAddonUpdate that might need to be updated

echo "Checking for references to the old type name PlanAddonUpdate:"
rg -A 2 -B 2 "PlanAddonUpdate" --type go

Length of output: 28422


Verify PlanAddonUpdate rename and new fields across the codebase

We ran a search for references to the old type name PlanAddonUpdate and found it still used in several internal packages. Before merging breaking changes to the API contract, please ensure existing clients and integrations are updated (or made backward‑compatible) for the renamed type and any added fields:

• productcatalog/planaddon/assert.go
• productcatalog/planaddon/event.go
• productcatalog/planaddon/adapter/adapter_test.go
• productcatalog/planaddon/service/service_test.go
• productcatalog/planaddon/service/planaddon.go
• ent/db/client.go
• ent/db/planaddon_update.go
• ent/db/setorclear.go

If your API clients import any of these types or rely on JSON payloads emitted by the service, update them accordingly or provide compatibility shims.

api/openapi.yaml (5)

18247-18251: Added optional metadata field to PlanAddon schema
You’ve correctly extended the PlanAddon schema with an optional metadata property using the shared Metadata component. It’s not in required, so existing clients won’t break.


18304-18314: Enhanced PlanAddonCreate with addon requirement and metadata support

  • Added - addon to the required list, ensuring the add-on ID must be provided.
  • Introduced an optional metadata property, composed via allOf from Metadata.
  • Reordered fromPlanPhase and addon to match the intended operation sequence.

18331-18333: Documented addon object and create request

  • Added a clear description and title for the inline addon object.
  • Provided a top‑level description for the PlanAddonCreate request schema.
    This improves readability and auto‑generated docs.

18369-18378: Introduced PlanAddonReplaceUpdate with metadata

  • Defined the PlanAddonReplaceUpdate schema, matching the renamed update model.
  • Included an optional metadata property composed from the shared Metadata schema.
  • Kept fromPlanPhase as the sole required field, since you cannot change the add‑on ID during an update.

7164-7164:

Details

✅ Verification successful

Updated schema reference for PUT operation
The PUT operation now correctly references the new PlanAddonReplaceUpdate schema, aligning with the renamed update model.

As a sanity check, ensure there are no remaining references to the old PlanAddonUpdate schema across the spec:


🏁 Script executed:

#!/bin/bash
# Verify no residual PlanAddonUpdate references
rg -n "PlanAddonUpdate"

Length of output: 9679


🏁 Script executed:

#!/bin/bash
# Search for any lingering references to the old schema in the OpenAPI spec
rg -n "PlanAddonUpdate" api/openapi.yaml

Length of output: 40


Confirm no lingering PlanAddonUpdate references
Ran rg -n "PlanAddonUpdate" api/openapi.yaml against the OpenAPI spec—no matches found. The spec is clean.

api/openapi.cloud.yaml (4)

7165-7165: Rename request schema to PlanAddonReplaceUpdate
The request body schema reference has been updated to the newly named PlanAddonReplaceUpdate, which aligns with the PR’s goal of unifying the update model.


17870-17874: Add optional metadata to the PlanAddon schema
Introducing the metadata field via allOf with the shared Metadata schema correctly makes it optional and non‑breaking for existing clients.


17927-17937: Include metadata in PlanAddonCreate request
The PlanAddonCreate schema now exposes metadata and explicitly requires addon, ensuring that clients must provide the add‑on while keeping metadata optional.


17992-18001: Verify fields in PlanAddonReplaceUpdate schema
The PlanAddonReplaceUpdate model currently requires only fromPlanPhase and adds metadata as optional. Confirm that omitting fields like addon (or other properties) from required is intentional for the replace/update contract, and that clients can still perform full replacements as expected.

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

4-5: Good addition of the lo library.

Adding the github.com/samber/lo package provides useful utility functions like ToPtr that simplify pointer handling in Go.


30-30: LGTM - Consistent metadata field handling.

The addition of the metadata field to the response structure properly aligns with the PR objectives to add metadata support for plan add-on assignments.


50-62: Clean implementation of metadata conversion.

The FromMetadata function follows the same pattern as the existing FromAnnotations function, maintaining code consistency while properly handling nil/empty metadata cases.


65-69: Looks good - Proper nil metadata handling.

The implementation properly checks if metadata is nil before attempting to convert it, preventing potential nil pointer dereferences.

Also applies to: 75-75


85-91: API signature update properly implemented.

The function signature has been correctly updated to use api.PlanAddonReplaceUpdate instead of api.PlanAddonUpdate, aligning with the broader API changes mentioned in the summary. The metadata handling is consistent with other functions while using lo.ToPtr appropriately for pointer conversion.

Also applies to: 96-96


106-118: Clean implementation of reverse metadata conversion.

The AsMetadata function properly handles the conversion from API to internal model metadata, following the same pattern as other conversion functions and correctly handling empty maps.

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

7208-7212: LGTM: Added metadata field to PlanAddon interface.

The addition of an optional metadata field with proper JSDoc documentation aligns with the PR objectives to support metadata in plan add-on assignments.


7253-7259: LGTM: Added JSDoc and metadata field to PlanAddonCreate model.

The metadata field has been properly added with descriptive JSDoc comments, maintaining code consistency with other API models.


7309-7314: LGTM: Renamed and updated PlanAddonReplaceUpdate model.

The model has been renamed from PlanAddonUpdate to PlanAddonReplaceUpdate and enhanced with the metadata field. This change improves semantics by clarifying that this is for a replace operation.


9855-9856: LGTM: Updated type export for renamed model.

The exported type has been correctly updated to match the renamed schema.


19219-19219: LGTM: Updated request body schema reference.

The operation now correctly references the renamed PlanAddonReplaceUpdate schema, maintaining consistency across the API.

@chrisgacsal chrisgacsal merged commit b0b2c39 into main Apr 16, 2025
28 checks passed
@chrisgacsal chrisgacsal deleted the feat/productcatalog branch April 16, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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