Skip to content

chore(api): simplify ConvertMetadataToLabels using maps.Clone and lo.…#3915

Open
borbelyr-kong wants to merge 3 commits intomainfrom
chore/simplify-metadata-to-labels
Open

chore(api): simplify ConvertMetadataToLabels using maps.Clone and lo.…#3915
borbelyr-kong wants to merge 3 commits intomainfrom
chore/simplify-metadata-to-labels

Conversation

@borbelyr-kong
Copy link
Contributor

@borbelyr-kong borbelyr-kong commented Mar 3, 2026

Summary by CodeRabbit

  • Refactor
    • Internal metadata label handling across API handlers was improved to ensure null-safe label returns and avoid accidental mutations, increasing reliability without changing public APIs.
  • Improvement
    • Query parameter parsing was tightened to more reliably recognize date-time values, reducing parsing/validation issues for date-time query inputs.

@borbelyr-kong borbelyr-kong requested a review from a team as a code owner March 3, 2026 14:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e2d67d and 57834b6.

⛔ Files ignored due to path filters (3)
  • api/client/go/client.gen.go is excluded by !api/client/**
  • api/client/javascript/src/client/schemas.ts is excluded by !api/client/**
  • api/client/javascript/src/zod/index.ts is excluded by !api/client/**
📒 Files selected for processing (1)
  • api/api.gen.go

📝 Walkthrough

Walkthrough

Refactored ConvertMetadataToLabels across multiple handlers to return non-nil *api.Labels by using maps.Clone + pointer wrapping; added stdlib maps and github.com/samber/lo imports. Also updated an OpenAPI-generated binding to use BindQueryParameterWithOptions for a date-time query parameter.

Changes

Cohort / File(s) Summary
Metadata-to-Labels Conversion Refactor
api/v3/handlers/apps/convert.go, api/v3/handlers/billingprofiles/convert.go, api/v3/handlers/customers/convert.go, api/v3/handlers/meters/convert.go, api/v3/handlers/subscriptions/convert.go, api/v3/handlers/taxcodes/convert.go
ConvertMetadataToLabels now early-returns &api.Labels{} for nil/empty input; for non-empty input it returns a pointer to a cloned map via maps.Clone cast to api.Labels and wrapped with lo.ToPtr. Added imports for maps and github.com/samber/lo. Replaced manual map population with clone-and-wrap.
OpenAPI binding change
api/api.gen.go
Replaced runtime.BindQueryParameter(...) with runtime.BindQueryParameterWithOptions(..., runtime.BindQueryParameterOptions{Type:"string", Format:"date-time"}) for the at query param, adding explicit type/format options to parsing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

release-note/ignore

Suggested reviewers

  • gergely-kurucz-konghq
  • tothandras
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring ConvertMetadataToLabels functions across multiple files to use maps.Clone and lo.ToPtr for cleaner implementation.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/simplify-metadata-to-labels

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.

@borbelyr-kong borbelyr-kong added the release-note/misc Miscellaneous changes label Mar 3, 2026
@gergely-kurucz-konghq
Copy link
Contributor

gergely-kurucz-konghq commented Mar 3, 2026

Not necessarily in scope for this PR, but just wondering if we can somehow extract the refactored conversion function to a common place, after seeing it being repeated in multiple places. The Metadata -> Labels conversion seems to be a common concern. Something to think about. It might not worth it, or might not be simple with goverter.

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