在 adonis5 我目前正在使用基于模式的验证,但这些验证仅适用于请求正文。我如何验证路径和查询参数验证
import { rules, schema } from '@ioc:Adonis/Core/Validator'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
class UserValidator {
async createUser(ctx: HttpContextContract) {
const createUserSchema = schema.create({
firstName: schema.string({
escape: true,
trim: true,
}, [
rules.minLength(3),
]),
lastName: schema.string({
escape: true,
trim: true
}, [
rules.minLength(3)
]),
email: schema.string({}, [
rules.email({
sanitize: true,
ignoreMaxLength: true,
domainSpecificValidation: true,
}),
rules.unique({
table: 'users',
column: 'email'
})
]),
password: schema.string({}, [
rules.minLength(8)
])
})
await ctx.request.validate({
schema: createUserSchema,
messages: {
'required': '{{field}} is required to create an account.',
'minLength': '{{field}} must be atleast {{options.minLength}} characters',
'unique': '{{field}} should be {{rule}}',
}
})
}