【问题标题】:How to check property is required or not in Joi如何在 Joi 中检查财产是否需要
【发布时间】:2023-04-06 02:43:01
【问题描述】:

我想将 required 分配给 client_idclient_secret 如果这些属性之一不为空,我必须检查 Joi 分配它 required Joi我怎么检查这个

schema = Joi.Object().keys({
    account_id: Joi.string().required(),
    client_id: Joi.string(),   // in client_id or client_secret //
    client_secret: Joi.string() // one must be required I have to check for This in Joi
});

【问题讨论】:

    标签: node.js npm optional required joi


    【解决方案1】:

    您可以使用object.or 解决此问题

    schema = Joi.Object().keys({
        account_id: Joi.string().required(),
        client_id: Joi.string(),   // in client_id or client_secret //
        client_secret: Joi.string() // one must be required I have to check for This in Joi
    }).or('client_id', 'client_secret');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多