Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add query support to features endpoint (#2693)
## About the changes The deprecated /api/admin/features endpoint supported querying with tag and namePrefix parameters. This PR adds this functionality to /api/admin/projects/<project>/features as well, allowing to replicate queries that used to work. Closes #2306 ### Important files src/lib/db/feature-strategy-store.ts src/test/e2e/stores/feature-strategies-store.e2e.test.ts ## Discussion points I'm extending our query parameters support for /api/admin/projects/<projectId>/features endpoint. This will be reflected in our open-api spec, so I also made an adminFeaturesQuerySchema for this. Also, very open for something similar to what we did for the modifyQuery for the archived parameter, but couldn't come up with a good way to support subselects using the query builder, it just ended up blowing the stack. If anyone has a suggestion, I'm all ears. Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
- Loading branch information
1 parent
1d1219a
commit eafba10
Showing
9 changed files
with
293 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { validateSchema } from '../validate'; | ||
import { AdminFeaturesQuerySchema } from './admin-features-query-schema'; | ||
|
||
test('adminFeaturesQuerySchema empty', () => { | ||
const data: AdminFeaturesQuerySchema = {}; | ||
|
||
expect( | ||
validateSchema('#/components/schemas/adminFeaturesQuerySchema', data), | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('adminFeatureQuerySchema all fields', () => { | ||
const data: AdminFeaturesQuerySchema = { | ||
tag: ['simple:some-tag', 'simple:some-other-tag'], | ||
namePrefix: 'some-prefix', | ||
}; | ||
|
||
expect( | ||
validateSchema('#/components/schemas/adminFeaturesQuerySchema', data), | ||
).toBeUndefined(); | ||
}); | ||
|
||
test('pattern validation should deny invalid tags', () => { | ||
const data: AdminFeaturesQuerySchema = { | ||
tag: ['something', 'somethingelse'], | ||
}; | ||
|
||
expect( | ||
validateSchema('#/components/schemas/adminFeaturesQuerySchema', data), | ||
).toBeDefined(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
|
||
export const adminFeaturesQuerySchema = { | ||
$id: '#/components/schemas/adminFeaturesQuerySchema', | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
tag: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
pattern: '\\w+:\\w+', | ||
}, | ||
description: | ||
'Used to filter by tags. For each entry, a TAGTYPE:TAGVALUE is expected', | ||
example: ['simple:mytag'], | ||
}, | ||
namePrefix: { | ||
type: 'string', | ||
description: | ||
'A case-insensitive prefix filter for the names of feature toggles', | ||
example: 'demo.part1', | ||
}, | ||
}, | ||
components: {}, | ||
} as const; | ||
|
||
export type AdminFeaturesQuerySchema = FromSchema< | ||
typeof adminFeaturesQuerySchema | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters