Skip to content

refactor(api): apply type conversion naming pattern#4135

Merged
tothandras merged 2 commits intomainfrom
chore/types-conversion-skill
Apr 13, 2026
Merged

refactor(api): apply type conversion naming pattern#4135
tothandras merged 2 commits intomainfrom
chore/types-conversion-skill

Conversation

@tothandras
Copy link
Copy Markdown
Contributor

@tothandras tothandras commented Apr 13, 2026

Summary by CodeRabbit

  • Documentation

    • Added a new style guide for type-conversion naming and file organization to standardize conversions across the codebase.
  • Refactor

    • Standardized conversion function names and mappings used by API handlers to improve consistency and reduce ambiguity in request/response transformations.

@tothandras tothandras added the release-note/ignore Ignore this change when generating release notes label Apr 13, 2026
@tothandras tothandras requested a review from a team as a code owner April 13, 2026 18:38
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b889c057-29b3-4334-8f25-c1ec6a49a6f3

📥 Commits

Reviewing files that changed from the base of the PR and between 57de92e and 97ef73c.

📒 Files selected for processing (46)
  • api/v3/handlers/apps/convert.gen.go
  • api/v3/handlers/apps/convert.go
  • api/v3/handlers/apps/get_app.go
  • api/v3/handlers/apps/list_app.go
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/billingprofiles/create.go
  • api/v3/handlers/billingprofiles/get.go
  • api/v3/handlers/billingprofiles/list.go
  • api/v3/handlers/billingprofiles/update.go
  • api/v3/handlers/currencies/convert.go
  • api/v3/handlers/currencies/create.go
  • api/v3/handlers/currencies/create_cost_basis.go
  • api/v3/handlers/currencies/get_cost_bases.go
  • api/v3/handlers/currencies/list.go
  • api/v3/handlers/customers/billing/convert.gen.go
  • api/v3/handlers/customers/billing/convert.go
  • api/v3/handlers/customers/billing/create_customer_stripe_checkout_session.go
  • api/v3/handlers/customers/billing/create_customer_stripe_portal_session.go
  • api/v3/handlers/customers/convert.gen.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/customers/get.go
  • api/v3/handlers/customers/list.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/featurecost/convert.go
  • api/v3/handlers/featurecost/query.go
  • api/v3/handlers/meters/convert.gen.go
  • api/v3/handlers/meters/convert.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/meters/get.go
  • api/v3/handlers/meters/list.go
  • api/v3/handlers/meters/query.go
  • api/v3/handlers/subscriptions/cancel.go
  • api/v3/handlers/subscriptions/change.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/subscriptions/create.go
  • api/v3/handlers/subscriptions/get.go
  • api/v3/handlers/subscriptions/list.go
  • api/v3/handlers/subscriptions/unschedule_cancelation.go
  • api/v3/handlers/taxcodes/convert.gen.go
  • api/v3/handlers/taxcodes/convert.go
  • api/v3/handlers/taxcodes/create.go
  • api/v3/handlers/taxcodes/get.go
  • api/v3/handlers/taxcodes/list.go
  • api/v3/handlers/taxcodes/update.go
✅ Files skipped from review due to trivial changes (14)
  • api/v3/handlers/apps/get_app.go
  • api/v3/handlers/meters/get.go
  • api/v3/handlers/billingprofiles/get.go
  • api/v3/handlers/featurecost/query.go
  • api/v3/handlers/meters/list.go
  • api/v3/handlers/apps/list_app.go
  • api/v3/handlers/taxcodes/list.go
  • api/v3/handlers/billingprofiles/create.go
  • api/v3/handlers/subscriptions/list.go
  • api/v3/handlers/taxcodes/create.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/taxcodes/update.go
  • api/v3/handlers/taxcodes/get.go
  • api/v3/handlers/taxcodes/convert.go
🚧 Files skipped from review as they are similar to previous changes (24)
  • api/v3/handlers/currencies/create.go
  • api/v3/handlers/customers/get.go
  • api/v3/handlers/currencies/get_cost_bases.go
  • api/v3/handlers/subscriptions/create.go
  • api/v3/handlers/subscriptions/get.go
  • api/v3/handlers/currencies/create_cost_basis.go
  • api/v3/handlers/customers/list.go
  • api/v3/handlers/billingprofiles/list.go
  • api/v3/handlers/customers/billing/create_customer_stripe_checkout_session.go
  • api/v3/handlers/subscriptions/unschedule_cancelation.go
  • api/v3/handlers/meters/query.go
  • api/v3/handlers/customers/billing/create_customer_stripe_portal_session.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/subscriptions/cancel.go
  • api/v3/handlers/featurecost/convert.go
  • api/v3/handlers/currencies/convert.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/taxcodes/convert.gen.go
  • api/v3/handlers/apps/convert.go
  • api/v3/handlers/customers/billing/convert.go
  • api/v3/handlers/meters/convert.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/customers/convert.gen.go

📝 Walkthrough

Walkthrough

This PR adds a skill spec for Go type-conversion naming and applies a large-scale rename: conversion helpers across api/v3/handlers/* are changed from generic Convert*/Map* names to directional From*/To* patterns (API/DB qualifiers and strict type suffixes), with matching call-site updates across ~40 files.

Changes

Cohort / File(s) Summary
Skill Specification
.agents/skills/go-types-conversion/SKILL.md
Added a new skill doc defining file/name conventions and strict From*/To* function naming rules for Go type conversions.
Apps
api/v3/handlers/apps/convert.gen.go, api/v3/handlers/apps/convert.go, api/v3/handlers/apps/get_app.go, api/v3/handlers/apps/list_app.go
Renamed app conversion variables/functions (e.g., MapAppToAPIToAPIBillingApp, ConvertAppsToBillingAppsToAPIBillingApps, catalog/type/page converters renamed) and updated call sites.
Billing Profiles
api/v3/handlers/billingprofiles/...
Comprehensive renames to directional From*/To* for addresses, app references, tax behavior/config, profile conversions; updated generated vars and handler call sites (create/get/list/update).
Currencies
api/v3/handlers/currencies/...
Renamed currency conversion helpers to FromAPIBillingCurrencyType, ToAPIBillingCurrency, ToAPIBillingCostBasis and updated call sites (create, list, cost-basis endpoints).
Customers
api/v3/handlers/customers/..., api/v3/handlers/customers/billing/...
Split/renamed create/upsert/list converters to FromAPICreateCustomerRequest, FromAPIUpsertCustomerRequest, ToAPIBillingCustomer, and Stripe-specific converters to FromAPIBillingAppStripe*/ToAPIBillingAppStripe*; updated handlers.
Feature Cost
api/v3/handlers/featurecost/convert.go, .../query.go
Renamed ConvertCostQueryResultToAPIToAPIFeatureCostQueryResult and related helpers; updated query handler.
Meters
api/v3/handlers/meters/...
Renamed create-request, aggregation, query, and pagination converters to FromAPICreateMeterRequest, ToAPIMeter*, FromAPIMeterAggregation/ToAPIMeterAggregation; updated handlers.
Subscriptions
api/v3/handlers/subscriptions/...
Renamed subscription converters (timing enums, create workflow, subscription → API) to FromAPIBillingSubscription* / ToAPIBillingSubscription; updated cancel/change/create/get/list/unschedule handlers.
Tax Codes
api/v3/handlers/taxcodes/...
Renamed create/upsert and taxcode→API converters to FromAPICreateTaxCodeRequest, FromAPIUpsertTaxCodeRequest, ToAPIBillingTaxCode, plus app-mappings/app-type helpers; updated handlers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

area/api

Suggested reviewers

  • chrisgacsal
  • borbelyr-kong
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary change: systematically renaming conversion functions throughout the codebase to follow a consistent FromAPI* and ToAPI* naming pattern.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/types-conversion-skill

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (1)
api/v3/handlers/subscriptions/convert.go (1)

17-35: Optional readability tweak: avoid subscription name shadowing.

Totally works as-is, but renaming the function param (e.g. sub) would make this a bit easier to read.

Suggested refactor
-func ToAPIBillingSubscription(subscription subscription.Subscription) api.BillingSubscription {
+func ToAPIBillingSubscription(sub subscription.Subscription) api.BillingSubscription {
 	subscriptionAPI := api.BillingSubscription{
-		Id:            subscription.ID,
-		CustomerId:    subscription.CustomerId,
-		BillingAnchor: subscription.BillingAnchor,
-		Status:        api.BillingSubscriptionStatus(subscription.GetStatusAt(clock.Now())),
-		Labels:        labels.FromMetadataAnnotations(subscription.Metadata, subscription.Annotations),
-		CreatedAt:     &subscription.CreatedAt,
-		UpdatedAt:     &subscription.UpdatedAt,
-		DeletedAt:     subscription.DeletedAt,
+		Id:            sub.ID,
+		CustomerId:    sub.CustomerId,
+		BillingAnchor: sub.BillingAnchor,
+		Status:        api.BillingSubscriptionStatus(sub.GetStatusAt(clock.Now())),
+		Labels:        labels.FromMetadataAnnotations(sub.Metadata, sub.Annotations),
+		CreatedAt:     &sub.CreatedAt,
+		UpdatedAt:     &sub.UpdatedAt,
+		DeletedAt:     sub.DeletedAt,
 	}
 
 	// Only set if the subscription is created from a plan
-	if subscription.PlanRef != nil {
-		subscriptionAPI.PlanId = &subscription.PlanRef.Id
+	if sub.PlanRef != nil {
+		subscriptionAPI.PlanId = &sub.PlanRef.Id
 	}

As per coding guidelines, “In general when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/v3/handlers/subscriptions/convert.go` around lines 17 - 35, The parameter
name subscription in ToAPIBillingSubscription shadows the package/type name and
hurts readability; rename the function parameter (for example change
subscription Subscription to sub subscription.Subscription) and update all
references inside the function (e.g., subscriptionAPI fields, the PlanRef check,
subscription.GetStatusAt(clock.Now()), subscription.Metadata,
subscription.Annotations, subscription.CreatedAt/UpdatedAt/DeletedAt, and
subscription.PlanRef.Id) so the code uses the new param name (sub) and preserves
existing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/skills/go-types-conversion/SKILL.md:
- Around line 91-94: Rename MapChargeFlatFeeFromDB to FromDBChargeFlatFee and
update all callers to use the new name; change the function currently named With
"FromAPI…" that actually converts domain -> API to ToAPIPlan (invert the
direction label) and remove its error return if it never fails; finally, in
SKILL.md fix the blockquote spacing by removing blank lines between consecutive
blockquote lines so markdownlint MD028 no longer fires.

---

Nitpick comments:
In `@api/v3/handlers/subscriptions/convert.go`:
- Around line 17-35: The parameter name subscription in ToAPIBillingSubscription
shadows the package/type name and hurts readability; rename the function
parameter (for example change subscription Subscription to sub
subscription.Subscription) and update all references inside the function (e.g.,
subscriptionAPI fields, the PlanRef check,
subscription.GetStatusAt(clock.Now()), subscription.Metadata,
subscription.Annotations, subscription.CreatedAt/UpdatedAt/DeletedAt, and
subscription.PlanRef.Id) so the code uses the new param name (sub) and preserves
existing behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b786f7af-731d-4048-84f8-3ebadf33a68f

📥 Commits

Reviewing files that changed from the base of the PR and between 5542629 and 57de92e.

📒 Files selected for processing (47)
  • .agents/skills/go-types-conversion/SKILL.md
  • api/v3/handlers/apps/convert.gen.go
  • api/v3/handlers/apps/convert.go
  • api/v3/handlers/apps/get_app.go
  • api/v3/handlers/apps/list_app.go
  • api/v3/handlers/billingprofiles/convert.gen.go
  • api/v3/handlers/billingprofiles/convert.go
  • api/v3/handlers/billingprofiles/create.go
  • api/v3/handlers/billingprofiles/get.go
  • api/v3/handlers/billingprofiles/list.go
  • api/v3/handlers/billingprofiles/update.go
  • api/v3/handlers/currencies/convert.go
  • api/v3/handlers/currencies/create.go
  • api/v3/handlers/currencies/create_cost_basis.go
  • api/v3/handlers/currencies/get_cost_bases.go
  • api/v3/handlers/currencies/list.go
  • api/v3/handlers/customers/billing/convert.gen.go
  • api/v3/handlers/customers/billing/convert.go
  • api/v3/handlers/customers/billing/create_customer_stripe_checkout_session.go
  • api/v3/handlers/customers/billing/create_customer_stripe_portal_session.go
  • api/v3/handlers/customers/convert.gen.go
  • api/v3/handlers/customers/convert.go
  • api/v3/handlers/customers/create.go
  • api/v3/handlers/customers/get.go
  • api/v3/handlers/customers/list.go
  • api/v3/handlers/customers/upsert.go
  • api/v3/handlers/featurecost/convert.go
  • api/v3/handlers/featurecost/query.go
  • api/v3/handlers/meters/convert.gen.go
  • api/v3/handlers/meters/convert.go
  • api/v3/handlers/meters/create.go
  • api/v3/handlers/meters/get.go
  • api/v3/handlers/meters/list.go
  • api/v3/handlers/meters/query.go
  • api/v3/handlers/subscriptions/cancel.go
  • api/v3/handlers/subscriptions/change.go
  • api/v3/handlers/subscriptions/convert.go
  • api/v3/handlers/subscriptions/create.go
  • api/v3/handlers/subscriptions/get.go
  • api/v3/handlers/subscriptions/list.go
  • api/v3/handlers/subscriptions/unschedule_cancelation.go
  • api/v3/handlers/taxcodes/convert.gen.go
  • api/v3/handlers/taxcodes/convert.go
  • api/v3/handlers/taxcodes/create.go
  • api/v3/handlers/taxcodes/get.go
  • api/v3/handlers/taxcodes/list.go
  • api/v3/handlers/taxcodes/update.go

Comment thread .agents/skills/go-types-conversion/SKILL.md
@tothandras tothandras force-pushed the chore/types-conversion-skill branch from 57de92e to 97ef73c Compare April 13, 2026 19:24
@tothandras tothandras enabled auto-merge (squash) April 13, 2026 19:26
@tothandras tothandras merged commit de9c118 into main Apr 13, 2026
23 checks passed
@tothandras tothandras deleted the chore/types-conversion-skill branch April 13, 2026 21:51
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