Skip to content

refactor(custom-currency): refactor custom currency API type#4631

Merged
borbelyr-kong merged 2 commits into
mainfrom
refactor/custom-currency
Jul 1, 2026
Merged

refactor(custom-currency): refactor custom currency API type#4631
borbelyr-kong merged 2 commits into
mainfrom
refactor/custom-currency

Conversation

@borbelyr-kong

@borbelyr-kong borbelyr-kong commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Fixed currency symbol handling across currency conversion and listing so returned data matches the optional nature of symbol.
    • Corrected fiat/custom currency symbol mapping during billing conversion.
  • API Model Updates

    • Updated fiat currency request/response schemas and types to remove id and description.
    • Refined custom currency schemas/types to align with the updated fiat/custom field composition.
  • Chores

    • Added yq-go to the default development environment tools.

@borbelyr-kong borbelyr-kong requested a review from a team as a code owner July 1, 2026 13:09
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 84693d9f-ef34-4532-a45b-4605a12c90c7

📥 Commits

Reviewing files that changed from the base of the PR and between d01bb96 and 10ea629.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (11)
  • api/spec/packages/aip-client-javascript/src/index.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/models/types.ts
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/currencies/convert.go
  • flake.nix
  • openmeter/currencies/adapter/currencies.go
  • openmeter/currencies/models.go
  • openmeter/currencies/service/service.go
  • openmeter/currencies/service/service_test.go
✅ Files skipped from review due to trivial changes (3)
  • openmeter/currencies/service/service_test.go
  • flake.nix
  • api/spec/packages/aip-client-javascript/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • openmeter/currencies/models.go
  • openmeter/currencies/adapter/currencies.go
  • openmeter/currencies/service/service.go
  • api/v3/handlers/currencies/convert.go
  • api/spec/packages/aip/src/currencies/currency.tsp

📝 Walkthrough

Walkthrough

This PR updates currency contracts across TypeSpec, generated JS client code, and Go runtime mappings to make Symbol optional and move id/description between fiat and custom currency shapes. It also adds yq-go to the default dev shell.

Changes

Currency schema and model rework

Layer / File(s) Summary
TypeSpec currency model source
api/spec/packages/aip/src/currencies/currency.tsp
CurrencyBase<T> removes id and description, and CurrencyCustom adds back id with read visibility.
Generated JS client types and schemas
api/spec/packages/aip-client-javascript/src/index.ts, api/spec/packages/aip-client-javascript/src/models/types.ts, api/spec/packages/aip-client-javascript/src/models/schemas.ts
CurrencyFiat is redefined without id or description, CurrencyCustom and CreateCurrencyCustomRequest are reshaped, and the CurrencyFiat re-export is relocated.
Go currency model and mapping
openmeter/currencies/models.go, openmeter/currencies/adapter/currencies.go, openmeter/currencies/service/service.go, openmeter/currencies/service/service_test.go, api/v3/handlers/currencies/convert.go
Currency.Symbol becomes optional, the adapter and service wrap symbols with lo.ToPtr, the API converter switches to direct symbol assignment, and tests use pointer-valued symbols.

Dev shell tooling

Layer / File(s) Summary
Add yq-go to dev shell
flake.nix
Adds yq-go to the default devenv shell package list.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: chrisgacsal, tothandras

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: refactoring the custom currency API type.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 refactor/custom-currency

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.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors the custom currency API shape and generated clients. The main changes are:

  • Moved custom-only fields out of the shared currency base model.
  • Removed description from custom currency request and response models.
  • Updated generated OpenAPI, Go, and TypeScript currency types.
  • Made currency symbols flow through the Go API as optional response fields.
  • Added yq-go to the default development shell.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
api/spec/packages/aip/src/currencies/currency.tsp Updates the currency TypeSpec models so fiat and custom currencies expose the intended fields.
api/v3/handlers/currencies/convert.go Maps optional currency symbols directly into the generated API response types.
openmeter/currencies/models.go Changes the domain currency symbol field to match the optional API response shape.
openmeter/currencies/service/service.go Builds fiat currency results using the updated optional symbol field.
openmeter/currencies/adapter/currencies.go Maps stored custom currency symbols into the updated domain model.
api/spec/packages/aip-client-javascript/src/models/types.ts Regenerates TypeScript currency interfaces for the updated fiat and custom currency fields.
api/spec/packages/aip-client-javascript/src/models/schemas.ts Regenerates zod currency schemas for the updated request and response shapes.
api/v3/openapi.yaml Regenerates OpenAPI currency schemas from the updated TypeSpec model.

Reviews (3): Last reviewed commit: "fix(custom-currency): fix review comment..." | Re-trigger Greptile

Comment thread api/spec/packages/aip/src/currencies/currency.tsp Outdated
@borbelyr-kong borbelyr-kong added the release-note/misc Miscellaneous changes label Jul 1, 2026

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/spec/packages/aip/src/currencies/currency.tsp (1)

42-47: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Tiny doc cleanup: id is no longer shared here.

The CurrencyBase comment still says id is shared by both currency types, but this PR moves id onto CurrencyCustom only.

Proposed fix
 /**
  * Describes the common properties of a currency. It is used as a base model for both standard currencies and custom currencies.
- * It includes properties such as id, name, and symbol that are shared by both types of currencies.
+ * It includes properties such as type, name, and symbol that are shared by both types of currencies.
  */

As per coding guidelines, “When refactoring or reverting code, preserve existing explanatory comments unless the code change makes them false, stale, or misleading.” As per path instructions, “The declared API should be accurate, in parity with the actual implementation, and easy to understand for the user.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/spec/packages/aip/src/currencies/currency.tsp` around lines 42 - 47, The
CurrencyBase model comment is stale because it still claims id is shared by both
currency types even though id now belongs only to CurrencyCustom. Update the
docstring on CurrencyBase to remove id from the shared-property description
while keeping the rest of the explanation aligned with the actual model shape.
Use the CurrencyBase and CurrencyCustom symbols to verify the comments match the
current API.

Sources: Coding guidelines, Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openmeter/currencies/adapter/currencies.go`:
- Line 31: The currency mapping in currencies adapter should preserve optional
semantics for Symbol instead of always wrapping the DB value with lo.ToPtr.
Update the mapping logic in the conversion function that builds the domain
currency model so that an empty DB Symbol becomes nil, while non-empty values
still become a pointer; this keeps the API type’s omitempty behavior and
distinguishes “unset” from “empty string”.

---

Outside diff comments:
In `@api/spec/packages/aip/src/currencies/currency.tsp`:
- Around line 42-47: The CurrencyBase model comment is stale because it still
claims id is shared by both currency types even though id now belongs only to
CurrencyCustom. Update the docstring on CurrencyBase to remove id from the
shared-property description while keeping the rest of the explanation aligned
with the actual model shape. Use the CurrencyBase and CurrencyCustom symbols to
verify the comments match the current API.
🪄 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: 48a9eaf9-4a1f-45f8-82ce-5f2cfdd3d1e9

📥 Commits

Reviewing files that changed from the base of the PR and between 91f1e5a and 9750adf.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (11)
  • api/spec/packages/aip-client-javascript/src/index.ts
  • api/spec/packages/aip-client-javascript/src/models/schemas.ts
  • api/spec/packages/aip-client-javascript/src/models/types.ts
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/v3/api.gen.go
  • api/v3/handlers/currencies/convert.go
  • flake.nix
  • openmeter/currencies/adapter/currencies.go
  • openmeter/currencies/models.go
  • openmeter/currencies/service/service.go
  • openmeter/currencies/service/service_test.go

Code: c.Code,
Name: c.Name,
Symbol: c.Symbol,
Symbol: lo.ToPtr(c.Symbol),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Empty DB symbol becomes non-nil pointer to "".

lo.ToPtr(c.Symbol) unconditionally wraps the DB value, so if Symbol is stored as an empty string (now that it's meant to be optional), the domain model will have a non-nil *string pointing to "" rather than nil. That defeats the omitempty tag on the API type and downstream consumers can't distinguish "no symbol" from "symbol is empty string".

🩹 Suggested fix
-		Symbol:       lo.ToPtr(c.Symbol),
+		Symbol:       lo.EmptyableToPtr(c.Symbol),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Symbol: lo.ToPtr(c.Symbol),
Symbol: lo.EmptyableToPtr(c.Symbol),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openmeter/currencies/adapter/currencies.go` at line 31, The currency mapping
in currencies adapter should preserve optional semantics for Symbol instead of
always wrapping the DB value with lo.ToPtr. Update the mapping logic in the
conversion function that builds the domain currency model so that an empty DB
Symbol becomes nil, while non-empty values still become a pointer; this keeps
the API type’s omitempty behavior and distinguishes “unset” from “empty string”.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@borbelyr-kong borbelyr-kong force-pushed the refactor/custom-currency branch from d01bb96 to 10ea629 Compare July 1, 2026 13:33
@borbelyr-kong borbelyr-kong merged commit ede95f6 into main Jul 1, 2026
29 checks passed
@borbelyr-kong borbelyr-kong deleted the refactor/custom-currency branch July 1, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/misc Miscellaneous changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants