1
父PARAMS我如何能實現的東西像下面的邏輯查詢參數驗證:驗證子PARAMS依賴於與淳佳和哈皮
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')
謝謝,那可以工作 – punkish