Build on the existing ValidateBody hook to apply the same approach to validate the entire request.query object. In cases where an endpoint has many query parameters, it's unnecessarily verbose to use the ValidateQueryParam hook on each individual parameter.
Propose to factor out the schema validation from ValidateBody into a shared helper, and leverage that in the existing ValidateBody hook and a new ValidateQuery hook.
Using an example from packages/cli/specs/rest-api/controllers/test-foo-bar.controller.auth.ts would now look like the following:
@Get()
@ApiOperationId('findTestFooBars')
@ApiOperationSummary('Find testFooBars.')
@ApiOperationDescription(
'The query parameters "skip" and "take" can be used for pagination. The first ' +
'is the offset and the second is the number of elements to be returned.'
)
@ApiResponse(400, { description: 'Invalid query parameters.' })
@ApiResponse(200, { description: 'Returns a list of testFooBars.' })
@ValidateQuery(QuerySchemaValidator)
async findTestFooBars(ctx: Context<User>) {
Build on the existing
ValidateBodyhook to apply the same approach to validate the entirerequest.queryobject. In cases where an endpoint has many query parameters, it's unnecessarily verbose to use theValidateQueryParamhook on each individual parameter.Propose to factor out the schema validation from
ValidateBodyinto a shared helper, and leverage that in the existingValidateBodyhook and a newValidateQueryhook.Using an example from
packages/cli/specs/rest-api/controllers/test-foo-bar.controller.auth.tswould now look like the following: