【发布时间】:2020-01-13 06:47:32
【问题描述】:
给定以下示例 POST 正文:
User = {
email: string; //required, email
password: string; //required, min length 8
profile: {
firstName: string; //required
lastName: string; //required
gender: Gender; //required, enum (M/F)
}
}
如何定义一个 express ValidationSchema 来验证嵌套的 Profile 对象及其在 User 中的道具
userValidatorSchema: ValidationSchema = {
email: {
isEmail: {}
},
password: {
exists: {
options: {checkNull: true},
errorMessage: 'Null value'
},
isEmpty: {
negated: true,
errorMessage: 'Empty string'
}
}
//Profile validation??
Express-validator docs 让它看起来像是 express-validator 无法实现的。如果是这样,什么是更通用的 express 验证器?
【问题讨论】: