Docs/DTOs
@validateProperty
DTOs are plain TypeScript classes with decorated properties. They define how request data is validated, transformed, and documented.
A DTO class may extend another one: it has the decorated properties of its parents as well as its own (class UserDto extends ContactDto), and a property decorated again in the subclass replaces the parent's definition.
validateProperty
Validates an incoming property value. Runs before your handler.
TypeScript
import { validateProperty } from 'alado';
class CredentialsDto {
@validateProperty({
required: true,
handler: (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value),
error: {
statusCode: 400,
message: 'Invalid email address',
},
})
email: string = 'user@example.com';
}handlerreceives the raw value and must returnboolean | Promise<boolean>- returning
false→ framework returns the configurederrorautomatically handleris called withthisbound to the fullRequestobject — you can accessthis.auth,this.query, etc.- do not use arrow functions if you need access to
this required: truerefuses a request without the field. A validator built with.required()does the same, sovalidate.string().email().required().build()needs norequired: truenext to it. Before 3.9.20 such a field was optional: a validator runs only on a value that is present, so a request without the field passed- a validator built with
validatealso gives the field's OpenAPI schema: see @documentProperty