Joi validation of array

后端 未结 6 946
梦如初夏
梦如初夏 2021-02-02 05:29

trying to validate that an array has zero or more strings in one case and that it has zero or more objects in another , struggling with Joi docs :(

validate: {
          


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 06:11

    validate: {
            headers: Joi.object({
                    'content-type': "application/vnd.api+json",
                    accept: "application/vnd.api+json"
            }).options({ allowUnknown: true }),
            payload : Joi.object().keys({
                data : Joi.object().keys({
                    type: Joi.any().allow('BY_TEMPLATE').required(),
                    attributes: Joi.object({
                        to : Joi.string().email().required(),
                        templateId : Joi.string().required(),
                        categories : Joi.array().items(Joi.string()),
                        variables : Joi.array().items(Joi.object().keys().max(1))
                    })
                }).required()
            })
        }
    

提交回复
热议问题