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:
parent
dab06cb1a9
commit
5c504ab9d4
2 changed files with 29 additions and 0 deletions
|
@ -37,6 +37,7 @@ import { buildOperationId, customRoutes, throwByDifference } from './utils/opera
|
||||||
import {
|
import {
|
||||||
buildParameters,
|
buildParameters,
|
||||||
paginationParameters,
|
paginationParameters,
|
||||||
|
searchParameters,
|
||||||
buildPathIdParameters,
|
buildPathIdParameters,
|
||||||
mergeParameters,
|
mergeParameters,
|
||||||
customParameters,
|
customParameters,
|
||||||
|
@ -50,12 +51,25 @@ const anonymousPaths = new Set<string>([
|
||||||
'status',
|
'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 = {
|
type RouteObject = {
|
||||||
path: string;
|
path: string;
|
||||||
method: OpenAPIV3.HttpMethods;
|
method: OpenAPIV3.HttpMethods;
|
||||||
operation: OpenAPIV3.OperationObject;
|
operation: OpenAPIV3.OperationObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
const buildOperation = (
|
const buildOperation = (
|
||||||
method: OpenAPIV3.HttpMethods,
|
method: OpenAPIV3.HttpMethods,
|
||||||
stack: IMiddleware[],
|
stack: IMiddleware[],
|
||||||
|
@ -72,6 +86,7 @@ const buildOperation = (
|
||||||
const queryParameters = [
|
const queryParameters = [
|
||||||
...buildParameters(query, 'query'),
|
...buildParameters(query, 'query'),
|
||||||
...(hasPagination ? paginationParameters : []),
|
...(hasPagination ? paginationParameters : []),
|
||||||
|
...(advancedSearchPaths.has(path) && method === 'get' ? [searchParameters] : []),
|
||||||
];
|
];
|
||||||
|
|
||||||
const requestBody = body && {
|
const requestBody = body && {
|
||||||
|
|
|
@ -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 = {
|
type BuildParameters = {
|
||||||
/**
|
/**
|
||||||
* Build a parameter array for the given `ZodObject`.
|
* Build a parameter array for the given `ZodObject`.
|
||||||
|
|
Loading…
Add table
Reference in a new issue