我想使用架构来验证JSON(当前是草案6,但如果需要,我们可以进行升级)。我的情况是一个对象,其属性值均具有相同的结构,例如:
{
"blueFoo": {
"bar1": "someValue",
"bar2": "differentValue"
},
"redFoo": {
"bar1": "someOtherValue",
"bar2": "LoremYpsum"
},
"purpleFoo": {
"bar1": "anotherString",
"bar2": "nextValue"
},
...
}
是否可以为常规属性值设置验证模式?像这样:
{
"type": "object",
"propertyValue": {
"type": "object",
"required": ["bar1", "bar2"],
"additionalProperties": false,
"properties": {
"bar1": {"type": "string"},
"bar2": {"type": "string"}
}
}
}
谢谢。
答案 0 :(得分:1)
additionalProperties
正是用于此目的:
{
"type": "object",
"additionalProperties": {
"properties": {
"bar1": {"type": "string"},
"bar2": {"type": "string"}
},
"required": ["bar1", "bar2"],
"additionalProperties": false
}
}