feat(api): simplify v3 query filter types#4218
Conversation
📝 WalkthroughWalkthroughThis change removes support for unknown/arbitrary filter operators across the codebase by eliminating the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/v3/api.gen.go (1)
4724-4750:⚠️ Potential issue | 🟠 MajorMake
and/orrecurse intoQueryFilterStringMapItem.Line 4726 and Line 4750 currently branch into
[]QueryFilterString, which drops theexistsoperator from any nested boolean expression. That makes valid map-item filters like{"or":[{"exists":false},{"eq":"foo"}]}impossible to represent with the generated Go types.Suggested shape after fixing the source schema and regenerating
type QueryFilterStringMapItem struct { // And Combines the provided filters with a logical AND. - And *[]QueryFilterString `json:"and,omitempty"` + And *[]QueryFilterStringMapItem `json:"and,omitempty"` @@ // Or Combines the provided filters with a logical OR. - Or *[]QueryFilterString `json:"or,omitempty"` + Or *[]QueryFilterStringMapItem `json:"or,omitempty"` }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@api/v3/api.gen.go` around lines 4724 - 4750, The And and Or fields on QueryFilterStringMapItem currently reference []QueryFilterString which prevents nested map-item operators like "exists" from being represented; change the types of And and Or on QueryFilterStringMapItem to *[]QueryFilterStringMapItem (so nested boolean expressions recurse into the same map-item shape), update any usages that construct or parse those fields to expect the new type, and regenerate or run codegen/tests to ensure the schema change is applied consistently.
🧹 Nitpick comments (1)
openmeter/productcatalog/feature/meter_group_by_filters_test.go (1)
13-50: Solid coverage for the new validation path! 👍The three sub-tests hit the key cases nicely: happy path, unknown dimension key, and the multi-operator rejection (which is really what this PR hinges on downstream).
Optional nit if you're feeling completionist: you could also add a tiny assertion that the returned error on the unknown-key case is (or wraps) a
*FeatureInvalidFiltersError— that way a future refactor that accidentally swallows the type still gets caught. Totally fine to skip.🧪 Optional extra assertion
t.Run("unknown dimension key", func(t *testing.T) { f := MeterGroupByFilters{ "nonexistent": filter.FilterString{Eq: lo.ToPtr("value")}, } err := f.Validate(m) require.Error(t, err) + var invalidErr *FeatureInvalidFiltersError + require.ErrorAs(t, err, &invalidErr) })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/productcatalog/feature/meter_group_by_filters_test.go` around lines 13 - 50, In the unknown-dimension-key sub-test of TestMeterGroupByFiltersValidate, add an assertion that the returned error from MeterGroupByFilters.Validate(m) is (or wraps) a *FeatureInvalidFiltersError to guard against type-swallowing refactors; keep the existing require.Error check, then use errors.As (or require.ErrorAs) to verify the concrete error type is *FeatureInvalidFiltersError, referencing MeterGroupByFilters.Validate and FeatureInvalidFiltersError so the test fails if the wrong error type is returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@api/v3/api.gen.go`:
- Around line 4724-4750: The And and Or fields on QueryFilterStringMapItem
currently reference []QueryFilterString which prevents nested map-item operators
like "exists" from being represented; change the types of And and Or on
QueryFilterStringMapItem to *[]QueryFilterStringMapItem (so nested boolean
expressions recurse into the same map-item shape), update any usages that
construct or parse those fields to expect the new type, and regenerate or run
codegen/tests to ensure the schema change is applied consistently.
---
Nitpick comments:
In `@openmeter/productcatalog/feature/meter_group_by_filters_test.go`:
- Around line 13-50: In the unknown-dimension-key sub-test of
TestMeterGroupByFiltersValidate, add an assertion that the returned error from
MeterGroupByFilters.Validate(m) is (or wraps) a *FeatureInvalidFiltersError to
guard against type-swallowing refactors; keep the existing require.Error check,
then use errors.As (or require.ErrorAs) to verify the concrete error type is
*FeatureInvalidFiltersError, referencing MeterGroupByFilters.Validate and
FeatureInvalidFiltersError so the test fails if the wrong error type is
returned.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5efd9ed2-75e5-4d34-9a95-853eeb0ca617
⛔ Files ignored due to path filters (1)
api/v3/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (11)
api/spec/packages/aip/src/shared/filters.tspapi/v3/api.gen.goapi/v3/handlers/features/create.goapi/v3/handlers/features/create_test.goapi/v3/handlers/meters/query/convert.goapi/v3/handlers/meters/query/convert_test.goapi/v3/handlers/meters/query/errors.goapi/v3/handlers/meters/query/params.goapi/v3/handlers/meters/query/params_test.goopenmeter/productcatalog/feature/feature.goopenmeter/productcatalog/feature/meter_group_by_filters_test.go
💤 Files with no reviewable changes (6)
- api/v3/handlers/features/create_test.go
- api/v3/handlers/meters/query/convert_test.go
- api/v3/handlers/meters/query/errors.go
- api/v3/handlers/meters/query/params.go
- api/v3/handlers/meters/query/convert.go
- api/spec/packages/aip/src/shared/filters.tsp
Summary by CodeRabbit
Release Notes
Bug Fixes
Refactor