@Validate(CreateUserSchema) // the body @Validate({ body:CreateUserSchema, query:Page }) // several sources @Validate('createUser') // a registered schema class
This knows nothing about the router, and that is the point: the declaration is recorded on the
handler itself, under this module's own key, so validation runs the same in a routed application,
a single-handler service, a CLI command or the browser. When a router is in play you may instead
put it on the route (@Post('/users', { validation: … })), which keeps the method uncluttered and
puts everything a route does in one place; both forms end up in the same middleware.
Method decorator: declare what a handler accepts.
This knows nothing about the router, and that is the point: the declaration is recorded on the handler itself, under this module's own key, so validation runs the same in a routed application, a single-handler service, a CLI command or the browser. When a router is in play you may instead put it on the route (
@Post('/users', { validation: … })), which keeps the method uncluttered and puts everything a route does in one place; both forms end up in the same middleware.