Is custom validation of the request body without classes possible? #1245
-
|
Thank you for the integration with class-transformer and class-validator. @Post("/users")
saveUser(@Body() user: User) { // will be be validated to `User` class by `class-transformer` and validated by `class-validator`
}But what if id don't want to create the separate class for each request body and want to use the another validator, for example, yup or RawObjectDataProcessor of the @yamato-daiwa/es-extensions? import { Post, Body } from "routing-controllers";
import AccessControlGateway from "@Gateways/AccessControl/AccessControlGateway";
@Controller()
export default class AccessControlController {
@Post("/api/sign_in")
protected async signIn(
@Body({ required: false }) requestData: AccessControlGateway.SigningIn.RequestData
): Promise<void> {
//
}
}where namespace AccessControlGateway {
export namespace SigningIn {
export type RequestData = Readonly<{
emailAddress: string;
password: string;
}>;
}
}I can't decide where I can specify the validation rules until will receive the answer, but it should be some middleware where I can access to the request body and validate it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can create your own middleware and annotate the methods with |
Beta Was this translation helpful? Give feedback.
You can create your own middleware and annotate the methods with
UseBefore. Currently it’s not possible to define your own validation through configuration so that’s your best bet at the moment.