英文:
Mark all object properties, including nested objects as required
问题
有没有一种默认的方式来做这个?而不是手动为每个属性进行操作?
如果可能的话,我希望它可以在 Joi.default 中完成。
const joi = Joi.defaults((schema) => {
return schema.strict().options({ stripUnknown: true })
})
英文:
Is there a way to do it by default? And not by hand for every property?
If it's possible, i hope it can be done in Joi.default
const joi = Joi.defaults((schema) => {
return schema.strict().options({ stripUnknown: true })
})
答案1
得分: 1
import Joi from '@hapi/joi'
const joi = Joi.defaults((schema) => {
return schema
.strict()
.options({ stripUnknown: true })
.presence('required')
})
export { joi }
英文:
Found a way, you can use presence('required'):
import Joi from '@hapi/joi'
const joi = Joi.defaults((schema) => {
return schema
.strict()
.options({ stripUnknown: true })
.presence('required')
})
export { joi }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论