fix: filter key normalization#652
Conversation
There was a problem hiding this comment.
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.gowith a reflection-based filter key normalization function that maps any-cased input to the correct camelCase API key - Replaced
strings.ToLower()withnormalizeFilterKey()inbuilder.go'ssetFiltersfunction - Updated and expanded tests in
builder_test.goto 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.
6dedd3b to
e09e93f
Compare
|



Commit aed0028 introduces a normalizer for filter keys which works in most cases i.e.
filters.Namecorrectly normalizes tofilters.namebut breaks certain camelCase keys such asimageType,createdBy.This PR introduces a normalization func which iterates through SDK Types and builds a filter map, and normalizes the filters correctly.