diff --git a/src/swagger/api-paginated-query.decorator.ts b/src/swagger/api-paginated-query.decorator.ts index 122b85b..6f13996 100644 --- a/src/swagger/api-paginated-query.decorator.ts +++ b/src/swagger/api-paginated-query.decorator.ts @@ -20,9 +20,14 @@ export function SortBy(paginationConfig: PaginateConfig) { ? paginationConfig.defaultSortBy.map(([col, order]) => `${col}:${order}`).join(',') : 'No default sorting specified, the result order is not guaranteed' + const sortBy = paginationConfig.sortableColumns.reduce((prev, curr) => { + return [...prev, `${curr}:ASC`, `${curr}:DESC`] + }, []) + return ApiQuery({ name: 'sortBy', isArray: true, + enum: sortBy, description: `Parameter to sort by.

To sort by multiple fields, just provide query param multiple types. The order in url defines an order of sorting

${p('Format', 'fieldName:DIRECTION')} diff --git a/src/swagger/pagination-docs.spec.ts b/src/swagger/pagination-docs.spec.ts index 56fa4aa..3345a8b 100644 --- a/src/swagger/pagination-docs.spec.ts +++ b/src/swagger/pagination-docs.spec.ts @@ -97,6 +97,7 @@ describe('PaginatedEndpoint decorator', () => { type: 'array', items: { type: 'string', + enum: ['id:ASC', 'id:DESC'], }, }, }, @@ -204,6 +205,7 @@ describe('PaginatedEndpoint decorator', () => { type: 'array', items: { type: 'string', + enum: ['id:ASC', 'id:DESC'], }, }, },