nestjs-paginate
nestjs-paginate copied to clipboard
Swagger integration
It would be nice to have swagger documentation support for the parameters. Currently it's not possible to change the limit, page or filter on the docs page.
Crude way I (partially) solved it:

true. some helper would be sweet
@20Koen02
I've created a custom decorator as a temporary solution. Works great
import { applyDecorators } from '@nestjs/common';
import { ApiQuery } from '@nestjs/swagger';
export function PaginateQueryOptions() {
return applyDecorators(
ApiQuery({ name: 'page', required: false }),
ApiQuery({ name: 'limit', required: false }),
ApiQuery({ name: 'search', required: false }),
ApiQuery({ name: 'sortBy', required: false }),
ApiQuery({ name: 'filter', required: false }),
);
}
@frankforpresident Starting from your example I extended it in order to give more information and include the searchBy field (found in the code but almost not documented elsewhere):
import { applyDecorators } from '@nestjs/common';
import { ApiQuery } from '@nestjs/swagger';
export function PaginateQueryOptions() {
return applyDecorators(
ApiQuery({ name: 'page', required: false, description: "Page number (starting from 1)", example: 1 }),
ApiQuery({ name: 'limit', required: false, description: "Number of records per page", example: 10 }),
ApiQuery({ name: 'search', required: false, description: "Multicolumn search term" }),
ApiQuery({ name: 'searchBy', required: false, description: "Limit columns to which apply 'search' term", isArray: true, type: 'string' }),
ApiQuery({ name: 'sortBy', required: false, description: "Format: _field_:_direction_ [direction may be ASC or DESC] e.g. id:DESC" }),
);
}
Concerning filter query, I'd rather add single @ApiQuery decorators to the involved controller, since this information is very specific to the single configuration and FilterOperators enabled. e.g.
@ApiQuery({ name: "filter.parentId", required: false, description: "Possible values: '$null' or '$eq:_id_' ", example: "$null" })
Here is a decorator that also generate a correct response schema, based on above answers
https://gist.github.com/TheToto/f29a8479393846b47961b2c8397a8217
Here is a decorator that also generate a correct response schema, based on above answers
https://gist.github.com/TheToto/f29a8479393846b47961b2c8397a8217
Good stuff ! Filter spec could be improve somewhat (see examples in https://github.com/ppetzold/nestjs-paginate#filters).
Also happy to accept a PR with swagger helpers ;)
:tada: This issue has been resolved in version 8.2.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: