Skip to content

Commit

Permalink
feat: schema for paginated applications (#6309)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Feb 22, 2024
1 parent ff70a92 commit 81ab77c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
57 changes: 57 additions & 0 deletions src/lib/openapi/spec/applications-query-parameters.ts
@@ -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>
>;
6 changes: 6 additions & 0 deletions src/lib/openapi/spec/applications-schema.ts
Expand Up @@ -7,8 +7,14 @@ export const applicationsSchema = {
additionalProperties: false,
description:
'An object containing a list of applications that have connected to Unleash via an SDK.',
required: ['total', 'applications'],
type: 'object',
properties: {
total: {
type: 'integer',
example: 50,
description: 'The total number of project applications.',
},
applications: {
description:
'The list of applications that have connected to this Unleash instance.',
Expand Down
5 changes: 4 additions & 1 deletion src/lib/routes/admin-api/metrics.ts
Expand Up @@ -23,6 +23,7 @@ import {
applicationOverviewSchema,
} from '../../openapi/spec/application-overview-schema';
import { OpenApiService } from '../../services';
import { applicationsQueryParameters } from '../../openapi/spec/applications-query-parameters';

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

async getApplication(
Expand Down

0 comments on commit 81ab77c

Please sign in to comment.