Skip to content

fix(api): add rest utility for nested visibility models for plan addons - #2676

Merged
tothandras merged 2 commits into
mainfrom
fix/plan-addon-api-visibility
Apr 16, 2025
Merged

tothandras merged 2 commits into
mainfrom
fix/plan-addon-api-visibility

Conversation

@tothandras

@tothandras tothandras commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor

TODO in a followup PR: migrate all TypeSpec.Rest models to OpenMeter.Rest that supports nested visibilities.

Summary by CodeRabbit

  • New Features

    • Introduced new resource operation models for improved API schema clarity and lifecycle visibility.
  • Refactor

    • Simplified plan add-on update and creation APIs by requiring only essential fields, removing detailed add-on metadata from request payloads.
    • Updated API schemas and endpoints to use new, streamlined models for plan add-on operations.
    • Standardized type references and model inheritance for resource operations across billing, customer, meter, and notification APIs.
  • Style

    • Enhanced visibility control for add-on properties in the product catalog.
  • Chores

    • Cleaned up import statements and namespace usage for improved code organization and consistency.

@tothandras
tothandras requested a review from chrisgacsal April 16, 2025 10:24
@tothandras
tothandras requested a review from a team as a code owner April 16, 2025 10:24
@coderabbitai

coderabbitai Bot commented Apr 16, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This change refactors the API models and schemas related to plan add-on updates across multiple languages and specification files. The PlanAddonReplaceUpdate model, which previously included a nested addon object with detailed fields, is replaced by a simplified PlanAddonUpdate model that only requires fromPlanPhase and optionally maxQuantity. Corresponding updates are made to OpenAPI specs, TypeScript, Go, and JavaScript client code, and the request body schemas for related endpoints. Additionally, resource model references are updated for consistency, and a new OpenMeter.Rest namespace is introduced with resource operation models using lifecycle-based visibility filtering.

Changes

Files/Paths Change Summary
api/api.gen.go, api/client/go/client.gen.go, api/client/javascript/src/client/schemas.ts Replaced PlanAddonReplaceUpdate struct/schema/type with simplified PlanAddonUpdate (removing nested addon fields); updated type aliases and embedded OpenAPI spec strings accordingly.
api/openapi.cloud.yaml, api/openapi.yaml Updated OpenAPI schemas and endpoint request body types to use PlanAddonUpdate instead of PlanAddonReplaceUpdate; simplified PlanAddonCreate and PlanAddonUpdate schemas to remove detailed nested addon fields.
api/spec/src/app/app.tsp, api/spec/src/app/stripe.tsp, api/spec/src/customer.tsp Changed resource model type references from Rest.Resource to TypeSpec.Rest.Resource in method signatures and property types.
api/spec/src/billing/invoices.tsp, api/spec/src/billing/profile.tsp, api/spec/src/meters.tsp Updated model inheritance and property types to use fully qualified TypeSpec.Rest.Resource references instead of Rest.Resource.
api/spec/src/notification/channel.tsp Changed model to implement TypeSpec.Rest.Resource.ResourceCreateModel instead of Rest.Resource.ResourceCreateModel.
api/spec/src/debug.tsp Removed using TypeSpec.Rest; import/directive without other changes.
api/spec/src/meters.tsp Removed using TypeSpec.Rest; import/directive; updated model signatures to fully qualified TypeSpec.Rest.Resource references.
api/spec/src/productcatalog/planaddon.tsp Added @visibility(Lifecycle.Read, Lifecycle.Create) decorator to addon property in PlanAddon model; removed unused using TypeSpec.Http; and using TypeSpec.OpenAPI;.
api/spec/src/productcatalog/routes.tsp Updated PlanAddons interface method body types to use new OpenMeter.Rest resource models for create and update operations.
api/spec/src/rest.tsp Introduced OpenMeter.Rest namespace with ResourceCreateModel, ResourceUpdateModel, and ResourceReplaceModel using lifecycle-based visibility filtering.
api/spec/src/billing/invoices/invoice.tsp Updated model inheritance to use fully qualified TypeSpec.Rest.Resource references instead of Rest.Resource.

Possibly related PRs


📜 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 65d2bd7 and f00cbe7.

📒 Files selected for processing (3)
  • api/spec/src/customer.tsp (2 hunks)
  • api/spec/src/meters.tsp (2 hunks)
  • api/spec/src/rest.tsp (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • api/spec/src/meters.tsp
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/spec/src/customer.tsp
  • api/spec/src/rest.tsp
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: CI
  • GitHub Check: Quickstart
  • GitHub Check: E2E
  • GitHub Check: Lint
  • GitHub Check: Developer environment
  • GitHub Check: Commit hooks
  • GitHub Check: Test
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Migration Checks
  • GitHub Check: Build
  • 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.

@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 (1)
api/openapi.cloud.yaml (1)

7044-7044: Plan add-on update schema simplification is correct and improves API clarity.

The switch to PlanAddonUpdate with only fromPlanPhase and maxQuantity is a breaking but positive change. It removes unnecessary fields from the update model, aligning the API with best practices and the actual update semantics.

If this is a public API, ensure consumers are notified of the breaking change.

Also applies to: 17776-17792

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e3b2a1 and e6e5d31.

📒 Files selected for processing (16)
  • api/api.gen.go (3 hunks)
  • api/client/go/client.gen.go (3 hunks)
  • api/client/javascript/src/client/schemas.ts (3 hunks)
  • api/openapi.cloud.yaml (2 hunks)
  • api/openapi.yaml (2 hunks)
  • api/spec/src/app/app.tsp (1 hunks)
  • api/spec/src/app/stripe.tsp (1 hunks)
  • api/spec/src/billing/invoices.tsp (5 hunks)
  • api/spec/src/billing/profile.tsp (2 hunks)
  • api/spec/src/customer.tsp (2 hunks)
  • api/spec/src/debug.tsp (0 hunks)
  • api/spec/src/meters.tsp (2 hunks)
  • api/spec/src/notification/channel.tsp (1 hunks)
  • api/spec/src/productcatalog/planaddon.tsp (1 hunks)
  • api/spec/src/productcatalog/routes.tsp (2 hunks)
  • api/spec/src/rest.tsp (1 hunks)
💤 Files with no reviewable changes (1)
  • api/spec/src/debug.tsp
🧰 Additional context used
🧬 Code Graph Analysis (3)
api/client/go/client.gen.go (2)
api/client/javascript/src/client/schemas.ts (1)
  • PlanAddonUpdate (9786-9786)
api/api.gen.go (1)
  • PlanAddonUpdate (4813-4820)
api/client/javascript/src/client/schemas.ts (2)
api/api.gen.go (1)
  • PlanAddonUpdate (4813-4820)
api/client/go/client.gen.go (1)
  • PlanAddonUpdate (4509-4516)
api/api.gen.go (2)
api/client/javascript/src/client/schemas.ts (1)
  • PlanAddonUpdate (9786-9786)
api/client/go/client.gen.go (1)
  • PlanAddonUpdate (4509-4516)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (21)
api/spec/src/rest.tsp (1)

13-43: Well-structured implementation of nested visibility models

The new OpenMeter.Rest namespace introduces three well-designed resource operation models that support lifecycle-based visibility filtering:

  • ResourceCreateModel with Lifecycle.Create visibility
  • ResourceUpdateModel with Lifecycle.Update visibility
  • ResourceReplaceModel with combined Lifecycle.Create or Lifecycle.Update visibility

This approach should effectively support nested visibility models as mentioned in the PR objectives, and provides a clean foundation for the planned migration from TypeSpec.Rest models.

api/spec/src/app/stripe.tsp (1)

174-174: Clean namespace qualification

Good update to use the fully qualified TypeSpec.Rest.Resource namespace instead of the shorter form. This makes the code more explicit and consistent with the changes across the codebase.

api/spec/src/notification/channel.tsp (1)

128-128: Consistent namespace qualification

Good update to use the fully qualified TypeSpec.Rest.Resource namespace, maintaining consistency with similar changes throughout the codebase.

api/spec/src/app/app.tsp (1)

52-52: Consistent namespace qualification

Good update to use the fully qualified TypeSpec.Rest.Resource namespace, matching the pattern applied across the codebase.

api/spec/src/meters.tsp (2)

167-167: Updated namespace reference for MeterCreate model

The change from Rest.Resource.ResourceCreateModel to TypeSpec.Rest.Resource.ResourceCreateModel uses fully qualified namespaces, which is more explicit and avoids ambiguity. This aligns with the broader effort to standardize resource model references across the codebase.


181-181: Updated namespace reference for MeterUpdate model

Similar to the MeterCreate model change, this updates to a fully qualified namespace reference. This change maintains consistency and prepares for the planned migration to OpenMeter.Rest mentioned in the PR objectives.

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

18-18: Added visibility decorator for nested addon object

Adding the @visibility(Lifecycle.Read, Lifecycle.Create) decorator to the addon property enables lifecycle-based visibility control at the object level, complementing the existing field-level visibility controls within the addon object. This is a key implementation of the PR's goal to support nested visibility models.

api/spec/src/customer.tsp (2)

26-26: Updated namespace reference in create method parameter

The change from a shorter namespace reference to the fully qualified TypeSpec.Rest.Resource.ResourceCreateModel<Customer> ensures consistency with similar changes across the codebase and avoids ambiguity in type resolution.


59-59: Updated namespace reference in update method parameter

Similarly, this change to TypeSpec.Rest.Resource.ResourceReplaceModel<Customer> maintains consistency in namespace references throughout the API specifications, which is important for the planned migration path described in the PR objectives.

api/api.gen.go (1)

4812-4820: PlanAddonUpdate struct and request body alias are correct and consistent with the new API contract

The new PlanAddonUpdate struct and the updated UpdatePlanAddonJSONRequestBody alias are well-defined, match the intended simplification, and are consistent with the coordinated changes across the codebase. No issues found.

Also applies to: 7403-7403

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

4508-4512: LGTM: Clean struct definition with good documentation

The new PlanAddonUpdate struct definition is well-documented with a clear purpose as a "Resource update operation model." This appears to be part of simplifying the API model by replacing the more complex PlanAddonReplaceUpdate with this streamlined version.


7035-7036: LGTM: Consistent type alias update

The update to UpdatePlanAddonJSONRequestBody correctly maps to the new PlanAddonUpdate struct, maintaining consistency with the model changes.


36602-37056: LGTM: Updated Swagger definition aligns with model changes

The updated embedded Swagger specification string reflects the API model changes, which is necessary for consistent API documentation. This change aligns with the PR's objective to support nested visibility models.

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

189-189: Changes to use the new OpenMeter.Rest namespace for model creation

The request body type changes from TypeSpec.Rest.Resource.ResourceCreateModel<PlanAddon> to OpenMeter.Rest.ResourceCreateModel<PlanAddon>, which aligns with the new REST utility for nested visibility models that this PR introduces.


210-210: Consistent use of OpenMeter.Rest namespace for model updates

The request body type changes from TypeSpec.Rest.Resource.ResourceReplaceModel<PlanAddon> to OpenMeter.Rest.ResourceUpdateModel<PlanAddon>, completing the transition to the custom REST utility that supports nested visibility filtering.

api/spec/src/billing/profile.tsp (2)

149-149: Consistent use of fully qualified namespace

The workflow property type is updated to use the fully qualified TypeSpec.Rest.Resource namespace, ensuring consistency within this file.


144-144:

Details

❓ Verification inconclusive

Different namespace pattern compared to productcatalog routes

While the productcatalog routes file has been updated to use the new OpenMeter.Rest namespace for resource models, this file explicitly uses the fully qualified TypeSpec.Rest.Resource namespace.

This inconsistency may indicate an incomplete migration. Consider if this file should also be updated to use the new OpenMeter.Rest namespace in a follow-up PR, as mentioned in the PR objectives about migrating all TypeSpec.Rest models to OpenMeter.Rest.

Also applies to: 168-168


🏁 Script executed:

#!/bin/bash
# Check for other files that still use TypeSpec.Rest.Resource vs those using OpenMeter.Rest
echo "Files using TypeSpec.Rest.Resource:"
rg -l "TypeSpec\.Rest\.Resource\." api/spec/src/

echo -e "\nFiles using OpenMeter.Rest:"
rg -l "OpenMeter\.Rest\." api/spec/src/

Length of output: 575


ACTION: Update namespace usage for consistency

The file api/spec/src/billing/profile.tsp (lines 144 and 168) still uses the old TypeSpec.Rest.Resource namespace, whereas the api/spec/src/productcatalog/routes.tsp file has already migrated to the OpenMeter.Rest namespace. A repository-wide scan confirms that several files (like meters.tsp, customer.tsp, subscription.tsp, etc.) are still using TypeSpec.Rest.Resource, with only the productcatalog routes updated.

Please verify if the migration objective to update all resource models to OpenMeter.Rest applies here. If it does, consider updating this file in a follow-up PR to maintain consistency across the codebase.

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

7237-7237: Schema rename aligns with simplified model structure.

This schema rename from PlanAddonReplaceUpdate to PlanAddonUpdate reflects the API model simplification described in the PR. The new model only focuses on essential update fields (fromPlanPhase and optional maxQuantity), matching the Go implementation in api/api.gen.go.


9786-9786: Type alias update is consistent with schema rename.

The type alias update correctly reflects the schema name change from PlanAddonReplaceUpdate to PlanAddonUpdate, ensuring type consistency throughout the client code.


19023-19023: Request body content type updated properly.

The request body content type for the update operation now correctly references the renamed PlanAddonUpdate schema, completing the model migration.

api/spec/src/billing/invoices.tsp (1)

505-505: Namespace qualification refactor is correct and safe.

The update from Rest.Resource to TypeSpec.Rest.Resource is a non-breaking, clarity-improving change. No issues found.

Also applies to: 536-536, 555-555, 564-564, 570-570, 624-624

Comment thread api/openapi.yaml Resolved
@tothandras
tothandras force-pushed the fix/plan-addon-api-visibility branch from e6e5d31 to 65d2bd7 Compare April 16, 2025 11:26
@tothandras tothandras added the release-note/bug-fix Release note: Bug Fixes label Apr 16, 2025
@tothandras tothandras changed the title fix(api): add rest utility for nested visibility models fix(api): add rest utility for nested visibility models for plan addons Apr 16, 2025
@tothandras
tothandras enabled auto-merge (squash) April 16, 2025 11:40
@tothandras
tothandras merged commit b15c9c9 into main Apr 16, 2025
@tothandras
tothandras deleted the fix/plan-addon-api-visibility branch April 16, 2025 12:04
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants