0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

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
This commit is contained in:
Mostafa Moradian 2024-08-01 04:58:02 +02:00 committed by GitHub
parent dab06cb1a9
commit 5c504ab9d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -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<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[],
@ -72,6 +86,7 @@ const buildOperation = (
const queryParameters = [
...buildParameters(query, 'query'),
...(hasPagination ? paginationParameters : []),
...(advancedSearchPaths.has(path) && method === 'get' ? [searchParameters] : []),
];
const requestBody = body && {

View file

@ -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`.