1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

feat: schema for paginated applications (#6309)

This commit is contained in:
Mateusz Kwasniewski 2024-02-22 12:18:23 +01:00 committed by GitHub
parent ff70a92956
commit 81ab77cf7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,57 @@
import { FromQueryParams } from '../util/from-query-params';
export const applicationsQueryParameters = [
{
name: 'query',
schema: {
type: 'string',
example: 'first_app',
},
description: 'The search query for the application name',
in: 'query',
},
{
name: 'offset',
schema: {
type: 'string',
example: '50',
},
description:
'The number of applications to skip when returning a page. By default it is set to 0.',
in: 'query',
},
{
name: 'limit',
schema: {
type: 'string',
example: '50',
},
description:
'The number of applications to return in a page. By default it is set to 1000.',
in: 'query',
},
{
name: 'sortBy',
schema: {
type: 'string',
example: 'type',
},
description:
'The field to sort the results by. By default it is set to "appName".',
in: 'query',
},
{
name: 'sortOrder',
schema: {
type: 'string',
example: 'desc',
},
description:
'The sort order for the sortBy. By default it is det to "asc".',
in: 'query',
},
] as const;
export type ApplicationsQueryParameters = Partial<
FromQueryParams<typeof applicationsQueryParameters>
>;

View File

@ -7,8 +7,14 @@ export const applicationsSchema = {
additionalProperties: false, additionalProperties: false,
description: description:
'An object containing a list of applications that have connected to Unleash via an SDK.', 'An object containing a list of applications that have connected to Unleash via an SDK.',
required: ['total', 'applications'],
type: 'object', type: 'object',
properties: { properties: {
total: {
type: 'integer',
example: 50,
description: 'The total number of project applications.',
},
applications: { applications: {
description: description:
'The list of applications that have connected to this Unleash instance.', 'The list of applications that have connected to this Unleash instance.',

View File

@ -23,6 +23,7 @@ import {
applicationOverviewSchema, applicationOverviewSchema,
} from '../../openapi/spec/application-overview-schema'; } from '../../openapi/spec/application-overview-schema';
import { OpenApiService } from '../../services'; import { OpenApiService } from '../../services';
import { applicationsQueryParameters } from '../../openapi/spec/applications-query-parameters';
class MetricsController extends Controller { class MetricsController extends Controller {
private logger: Logger; private logger: Logger;
@ -104,6 +105,7 @@ class MetricsController extends Controller {
summary: 'Get all applications', summary: 'Get all applications',
description: description:
'Returns all applications registered with Unleash. Applications can be created via metrics reporting or manual creation', 'Returns all applications registered with Unleash. Applications can be created via metrics reporting or manual creation',
parameters: [...applicationsQueryParameters],
operationId: 'getApplications', operationId: 'getApplications',
responses: { responses: {
200: createResponseSchema('applicationsSchema'), 200: createResponseSchema('applicationsSchema'),
@ -193,7 +195,8 @@ class MetricsController extends Controller {
query, query,
extractUserIdFromUser(user), extractUserIdFromUser(user),
); );
res.json({ applications }); // todo: change to total with pagination later
res.json({ applications, total: applications.length });
} }
async getApplication( async getApplication(