Skip to content

fix: filter key normalization#652

Merged
avirtopeanu-ionos merged 3 commits intomasterfrom
fix/filter-key-normalization
Mar 19, 2026
Merged

fix: filter key normalization#652
avirtopeanu-ionos merged 3 commits intomasterfrom
fix/filter-key-normalization

Conversation

@avirtopeanu-ionos
Copy link
Copy Markdown
Contributor

Commit aed0028 introduces a normalizer for filter keys which works in most cases i.e. filters.Name correctly normalizes to filters.name but breaks certain camelCase keys such as imageType, createdBy.

This PR introduces a normalization func which iterates through SDK Types and builds a filter map, and normalizes the filters correctly.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes filter key normalization for the IONOS Cloud CLI. The previous approach used simple strings.ToLower() which broke camelCase API filter keys like imageType and createdBy by converting them to imagetype and createdby. The new approach builds a lookup map from SDK struct types using reflection, enabling case-insensitive input while preserving the correct camelCase form expected by the API.

Changes:

  • Added internal/client/filter_keys.go with a reflection-based filter key normalization function that maps any-cased input to the correct camelCase API key
  • Replaced strings.ToLower() with normalizeFilterKey() in builder.go's setFilters function
  • Updated and expanded tests in builder_test.go to cover camelCase preservation, uppercase normalization, mixed-case merging, and unknown key pass-through

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/client/filter_keys.go New file implementing normalizeFilterKey(), buildFilterKeyMap(), and firstLower() using reflection on SDK property types to build a case-insensitive filter key lookup map
internal/client/builder.go One-line change replacing strings.ToLower(parts[0]) with normalizeFilterKey(parts[0]) in setFilters
internal/client/builder_test.go Updated existing tests and added new tests for camelCase preservation, uppercase normalization, mixed-case merging, and direct normalizeFilterKey unit tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/client/filter_keys.go Outdated
Comment thread internal/client/filter_keys.go Outdated
@avirtopeanu-ionos avirtopeanu-ionos force-pushed the fix/filter-key-normalization branch from 6dedd3b to e09e93f Compare March 19, 2026 11:28
@sonarqubecloud
Copy link
Copy Markdown

@avirtopeanu-ionos avirtopeanu-ionos merged commit df3e13d into master Mar 19, 2026
9 checks passed
@avirtopeanu-ionos avirtopeanu-ionos deleted the fix/filter-key-normalization branch March 19, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants