我使用 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 \\\
}
}
}
有人知道方法,如何实现吗?谢谢