【发布时间】:2017-12-11 21:40:50
【问题描述】:
我想检查一个模式中是否只有一个模式,或者它是否有多个具有 oneOf 属性的模式。
python 代码应该是这样的
If schema1 has oneOf property:
Some code1
If schema1 is just a single schema:
Some code2
基本上我希望能够区分这两种模式
架构1
"schema1": {
"definitions": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": ["string", "null"]
}
}
}
}
}
架构2
"schema2": {
"definitions": {
"schema": {
"oneOf": [
{
"type": ["null"]
},
{
"type": ["string"],
"enum": ["NONE"]
}
]
}
}
}
如何在 Python 中做到这一点?
编辑:更正了我的示例架构
【问题讨论】:
-
模式看起来“错误” - 它们是您正在使用的实际模式吗......如果是这样,对象本身明确说明它们是哪个模式。如果不是..请显示一些示例数据,您必须在其中确定哪个架构已到位。
-
@KeithJohnHutchison 我已经更正了问题中的示例架构。这不是我正在使用的确切架构,但与它相似。我的编辑现在是否纠正了架构,还是仍然错误?
标签: python json jsonschema json-schema-validator