【发布时间】:2019-11-07 17:01:10
【问题描述】:
我正在使用适用于 Python 的 jsonschema,并且我正在尝试允许以下任何一项:
{}
# or
{
'id': 'd6a4def3-4a6a-4fb4-a38e-f98ea48f708a'
}
# or
{
'status': 'Done'
}
但我不想允许以下内容,因为提供了两个字段:
{
'id': 'd6a4def3-4a6a-4fb4-a38e-f98ea48f708a',
'status': 'Done'
}
这是我目前所拥有的,它允许按照我的意愿提供一个或另一个字段,但它不允许任何内容。
GET_CALL = {
"type": "object",
"additionalProperties": False,
"properties": {
"id": {
"type": "string",
"pattern": REGEX_EXPRESSIONS['UUID4'], # Matches a UUID4 format
},
"status": {
"type": "string",
"enum": ["Done", "Ready"],
},
},
"oneOf": [ # This makes it so I can only have one or the other but it doesn't allow nothing.
{"required": ["id"]},
{"required": ["status"]}
],
}
【问题讨论】:
标签: python python-3.x jsonschema