标记所有对象属性,包括嵌套对象,为必需项。

huangapple go评论56阅读模式
英文:

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 }

huangapple
  • 本文由 发表于 2020年1月6日 19:37:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611439.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定