Skip to content

[@feat/core]: Apply the ValidateBody hook schema validation to request.query #1367

Description

@kingsthwaiteJ

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>) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions