比较joi中的两个对象
有没有办法验证一个对象中存在的密钥与另一个对象中存在的密钥相同?
例如:
{
"localizationName": "en-US",
"dataText": [
{
"persona": "gw_user",
"verbiage": "read all patient info gw_user"
},
{
"persona": "patient",
"verbiage": "read all patient info patient"
}
],
"purposeText": [
{
"persona": "gw_user",
"verbiage": "read all patient data <<purspose>> gw_user"
},
{
"persona": "patient",
"verbiage": "read all patient data <<purspose>> patient"
}
]
}
按照上述示例,“ datatext”&amp; amp; amp; amp; amp; “ peleseText”。
我想要“ datatext中存在的任何角色”的JOI验证代码,也应在“ peleSetext”中定义相同的角色。
以下是我可以提出的JOI验证代码。但这似乎不起作用。
localizationName: Joi.string()
.valid(...BCP47LanguageTags)
.required()
.messages({ 'any.only': '"localizationName" must be a BCP47 compliant language tag like "en-US"' }),
dataText: Joi.array().items(
Joi.object().keys({
persona: Joi.string().valid(...Persona).required(),
verbiage: Joi.string()
})
).required(),
purposeText: Joi.array().items(
Joi.object().keys({
persona: Joi.string().valid(Joi.in('dataText')).required(),
verbiage: Joi.string()
})
).required()
任何帮助将不胜感激。
Is there a way to verify that the key that exists in one object is the same as the key that exists in the other object?
For eg:
{
"localizationName": "en-US",
"dataText": [
{
"persona": "gw_user",
"verbiage": "read all patient info gw_user"
},
{
"persona": "patient",
"verbiage": "read all patient info patient"
}
],
"purposeText": [
{
"persona": "gw_user",
"verbiage": "read all patient data <<purspose>> gw_user"
},
{
"persona": "patient",
"verbiage": "read all patient data <<purspose>> patient"
}
]
}
As per the above example, the same personas exist in both "dataText" & "purposeText".
I want a joi validation code for 'whatever personas exist in the "dataText", the same personas should be defined in the "purposeText" as well'.
Below is the joi validation code I could come up with. But that doesn't seem to work.
localizationName: Joi.string()
.valid(...BCP47LanguageTags)
.required()
.messages({ 'any.only': '"localizationName" must be a BCP47 compliant language tag like "en-US"' }),
dataText: Joi.array().items(
Joi.object().keys({
persona: Joi.string().valid(...Persona).required(),
verbiage: Joi.string()
})
).required(),
purposeText: Joi.array().items(
Joi.object().keys({
persona: Joi.string().valid(Joi.in('dataText')).required(),
verbiage: Joi.string()
})
).required()
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我创建了一个函数,可用于比较所选对象指定键内的属性。我还假设您要比较的属性将在2个键中以相同的顺序为单位。
请参阅下面的代码:
I've created a function that can be used to compare properties within specified keys of a chosen object. I have also made assumptions that the properties you want to compare will be in the same order within the 2 keys.
See my code below: