Skip to content

Commit

Permalink
feat: add advanced search params to all supported endpoints (#6358)
Browse files Browse the repository at this point in the history
* feat: add search params to list users endpoint

* feat: implement advanced search for all supported endpoints
  • Loading branch information
mostafa authored Aug 1, 2024
1 parent dab06cb commit 5c504ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/core/src/routes/swagger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { buildOperationId, customRoutes, throwByDifference } from './utils/opera
import {
buildParameters,
paginationParameters,
searchParameters,
buildPathIdParameters,
mergeParameters,
customParameters,
Expand All @@ -50,12 +51,25 @@ const anonymousPaths = new Set<string>([
'status',
]);

const advancedSearchPaths = new Set<string>([
'/applications',
'/applications/:applicationId/roles',
'/resources/:resourceId/scopes',
'/roles/:id/applications',
'/roles/:id/scopes',
'/roles',
'/roles/:id/users',
'/users',
'/users/:userId/roles',
]);

type RouteObject = {
path: string;
method: OpenAPIV3.HttpMethods;
operation: OpenAPIV3.OperationObject;
};

// eslint-disable-next-line complexity
const buildOperation = (
method: OpenAPIV3.HttpMethods,
stack: IMiddleware[],
Expand All @@ -72,6 +86,7 @@ const buildOperation = (
const queryParameters = [
...buildParameters(query, 'query'),
...(hasPagination ? paginationParameters : []),
...(advancedSearchPaths.has(path) && method === 'get' ? [searchParameters] : []),
];

const requestBody = body && {
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/routes/swagger/utils/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export const paginationParameters: OpenAPIV3.ParameterObject[] = [
},
];

export const searchParameters: OpenAPIV3.ParameterObject = {
name: 'search_params',
in: 'query',
description: 'Search query parameters.',
required: false,
schema: {
type: 'object',
additionalProperties: {
type: 'string',
},
},
explode: true,
};

type BuildParameters = {
/**
* Build a parameter array for the given `ZodObject`.
Expand Down

0 comments on commit 5c504ab

Please sign in to comment.