gpt4 book ai didi

javascript - AJV 多级/嵌套 JSON 模式验证

转载 作者:行者123 更新时间:2023-11-30 19:54:03 25 4
gpt4 key购买 nike

使用架构

{
"type": "object",
"required": [
"person",
"animal"
],
"person": {
"title": "person",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
}
}
},
"animal": {
"title": "animal",
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
}
}

此架构在与此对象进行比较时有效

{
"person": 0,
"animal": "dog"
}

我只希望它验证 person 对象中的属性(因为它也有必需的属性)。例如,只有以下内容是有效的:

{
"person": {
"name": "myName"
},
"animal": "dog"
}

如何使用 AJV 确保嵌套对象在我的架构中得到验证?

最佳答案

在您的架构中,您需要将 animalperson 放入 properties 对象中。

目前,由于这些属性键不在 properties 对象中,因此它们被归类为未知关键字并被忽略。

否则,是的,你是对的。

关于javascript - AJV 多级/嵌套 JSON 模式验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54207956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com