【发布时间】:2014-09-18 15:17:46
【问题描述】:
所以,我正在尝试为一组轴约束定义一个模式。因此,我想将“axis”元素的可能值限制为[“x”,“y”,“z”]。
这是我当前的示例,它是输出。
JSON:
{
"name_patterns": [
{
"regex": "block[_-]?([\\d]*)",
"class": "block",
"id_group": 1
}
],
"relationships": [
{
"src_class": "block",
"dst_class": "block",
"constraints": {
"axis": "x"
}
}
]
}
架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"name_patterns": {"type": "array",
"items": { "$ref": "#/definitions/name_entry" } },
"relationships": {"type": "array",
"items": { "anyof": [ {"$ref": "#/definitions/relation"} ] } }
},
"definitions": {
"name_entry": {
"type": "object",
"properties": {
"regex": {"type": "string"},
"class": {"type": "string"},
"id_group": {"type": "number"}
},
"required": ["regex", "class"]
},
"relation": {
"type": "object",
"properties": {
"src_class": {"type": "string"},
"dst_class": {"type": "string"},
"constraints": {
"type": "object",
"properties": {
"axis": {
"enum": ["x", "y", "z"]
}
},
"required": ["axis"]
}
},
"required": ["src_class", "dst_class", "constraints"]
}
}
}
如何修复我的架构以拒绝未在枚举器中指定的值?
【问题讨论】:
标签: python json enums jsonschema