如何验证包含MIXED类型对象的json模式数组?

问题描述

我已经搜索了但还没有找到解决方法。

我想这样做:

...
"bag": {
   "type": "array","items": {
      "anyOf": [
         {"$ref": "#/definitions/obj1"},{"$ref": "#/definitions/obj2"},{"$ref": "#/definitions/obj3"}
      ]
   },"required": ["items"],"minItems": 1
}
...

已定义对象:

...
"definitions": {
   "obj1": {
      "type": "object","properties": {
         "obj1": {
            "type": "object","properties": {
                "a": {
                   "type": "string"
                }
            },"required": ["a"]
         }
      }
   },"obj2": {
      "type": "object","properties": {
                "b": {
                   "type": "string"
                }
            },"required": ["b"]
         }
      }
   },"obj3": {
      "type": "object","properties": {
                "c": {
                   "type": "string"
                }
            },"required": ["c"]
         }
      }
   }
}
...

理想情况下,我想针对如下所示的模式进行验证:

...
"bag": [
   {
      "obj1": {"a": "test1"}
   },{
      "obj3": {"c": "test1"}
   }
]
...

在这种情况下,如果有人将obj1obj3传递到bag中。根据模式,obj1需要属性a,而obj3需要属性c

由于验证似乎无法正确执行,我在实际执行此操作时遇到了麻烦。

有什么提示吗?预先感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)