我怎样才能实现验证了类似下面的逻辑查询参数:
if (type is 'image') {
subtype is Joi.string().valid('png', 'jpg')
else if (type is 'publication') {
subtype is Joi.string().valid('newspaper', 'book')
让无论是
server/?type=image&subtype=png
要么
server/?type=publication&subtype=book
但不能同时image
和publication
在同一时间?
更新:我尝试下面的代码,但没有运气
type: Joi
.string()
.valid('image', 'publication', 'dataset')
.optional(),
subtype: Joi
.when('type',
{
is: 'image',
then: Joi
.string()
.valid('png', 'jpg')
.optional()
},
{
is: 'publication',
then: Joi
.string()
.valid('newspaper', 'book')
.optional()
}
)
.optional()
.description('subtype based on the file_type')