A single schema means the body, which is what almost every route means; a map validates several
sources at once ({ body, query, params }).
This middleware reads that from the matched route and validates it. On success each parsed
source is published in the event's metadata under a predictable name, so a handler reads
event.get<CreateUser>('validatedBody') with no helper and no import. That matters more than it
looks: a schema coerces and strips, and re-reading the raw value is how an application validates
one thing and uses another. On failure it throws a ValidationError carrying every issue at once.
The route stays the single description of itself, which is what lets @stone-js/openapi publish
the request schema without being told a second time.
Route middleware: validates what a route declared, before its handler runs.
A route says what it accepts, once, where the route is defined:
A single schema means the body, which is what almost every route means; a map validates several sources at once (
{ body, query, params }).This middleware reads that from the matched route and validates it. On success each parsed source is published in the event's metadata under a predictable name, so a handler reads
event.get<CreateUser>('validatedBody')with no helper and no import. That matters more than it looks: a schema coerces and strips, and re-reading the raw value is how an application validates one thing and uses another. On failure it throws aValidationErrorcarrying every issue at once.The route stays the single description of itself, which is what lets
@stone-js/openapipublish the request schema without being told a second time.