【发布时间】:2018-10-22 16:43:18
【问题描述】:
我正在使用 Python 的 jsonschema 来验证 JSON 记录。这是一个示例架构。这里只有两个案例,但想象一个类似的场景,它有一百个这样的案例。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"oneOf": [
{
"type": "object",
"required": ["a", "b", "c"],
"properties": {
"a": {"type": "integer", "enum": [0]},
"b": {"type": "integer", "enum": [0, 2, 4, 6, 8]},
"c": {"type": "string", "enum": ["always the same"]}
}
},
{
"type": "object",
"required": ["a", "b", "c"],
"properties": {
"a": {"type": "integer", "enum": [1]},
"b": {"type": "integer", "enum": [1, 3, 5, 7, 9]},
"c": {"type": "string", "enum": ["always the same"]}
}
}
]
}
关键问题是"c" 字段的重复。我希望能够在"a" 上切换大小写,验证相应的"b",但"c" 始终保持不变。我不想把"c" 拼出一百次。这可以吗?
谢谢!
【问题讨论】:
标签: jsonschema python-jsonschema