From 5c504ab9d4401a7ddd2b906736a810b69c8dc873 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Thu, 1 Aug 2024 04:58:02 +0200 Subject: [PATCH] feat: add advanced search params to all supported endpoints (#6358) * feat: add search params to list users endpoint * feat: implement advanced search for all supported endpoints --- packages/core/src/routes/swagger/index.ts | 15 +++++++++++++++ .../core/src/routes/swagger/utils/parameters.ts | 14 ++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/packages/core/src/routes/swagger/index.ts b/packages/core/src/routes/swagger/index.ts index 1771c06d8..6248f9e08 100644 --- a/packages/core/src/routes/swagger/index.ts +++ b/packages/core/src/routes/swagger/index.ts @@ -37,6 +37,7 @@ import { buildOperationId, customRoutes, throwByDifference } from './utils/opera import { buildParameters, paginationParameters, + searchParameters, buildPathIdParameters, mergeParameters, customParameters, @@ -50,12 +51,25 @@ const anonymousPaths = new Set([ 'status', ]); +const advancedSearchPaths = new Set([ + '/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[], @@ -72,6 +86,7 @@ const buildOperation = ( const queryParameters = [ ...buildParameters(query, 'query'), ...(hasPagination ? paginationParameters : []), + ...(advancedSearchPaths.has(path) && method === 'get' ? [searchParameters] : []), ]; const requestBody = body && { diff --git a/packages/core/src/routes/swagger/utils/parameters.ts b/packages/core/src/routes/swagger/utils/parameters.ts index c7486c2ee..54356a409 100644 --- a/packages/core/src/routes/swagger/utils/parameters.ts +++ b/packages/core/src/routes/swagger/utils/parameters.ts @@ -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`.