【发布时间】:2020-05-22 11:39:42
【问题描述】:
我使用 Python 包 cerberus 来验证我的有效载荷 这是我的问题:
仅当来自另一个模式的某些字段具有精确值时,我才需要设置一个字段。比如:
"key2": {
"type": "string",
"required": \\\ true if dict1.key1 == 'valueX' else false \\\
}
所以我的架构应该是这样的:
"dict1": {
"type": "dict",
"schema": {
"key1": {
"type": "string",
"required": true
}
}
},
"dict2": {
"type": "dict",
"schema": {
"key2": {
"type": "string",
"required": \\\ true if dict1.key1 == 'valueX' else false \\\
}
}
}
有人知道方法吗,如何实现? 谢谢
【问题讨论】:
标签: python-3.x validation conditional-statements cerberus