我正在使用JOI进行架构验证。在以下架构中,我希望在input_file
为type
时jobType.MBR
属于file_name
,否则required
必须保持const jobObjectSchema = {
type: Joi.string().valid(jobType.MBR, jobType.MP4).required(),
file_name: Joi.string().required(),
input_file: Joi.string()
};
类型
select top 2 from (select TutionFee from TBLStudentFeeRecord
where StudentId = 1001
order by TutionFee desc )
我该怎么做?
答案 0 :(得分:1)
使用Joi
any().when
。
const jobObjectSchema = {
type: Joi.string().valid(jobType.MBR, jobType.MP4).required(),
file_name: Joi.any().when('type', {
is: jobType.MBR,
then: Joi.string().optional(),
otherwise: Joi.string().required()
}),
input_file: Joi.any().when('type', {
is: jobType.MBR,
then: Joi.string().required(),
otherwise: Joi.string().optional()
})
};