Cerberus:错误对象中的多余嵌套
Cerberus: superfluous nesting in the error object
我使用 cerberus 来验证我的数据,例如:
document = {
"region": 77,
"drivers": {
"data": [
{ "birthday": "2004-01-01", "kbm_class": "3", "driving_experience": 10 },
{ "birthday": "1988-01-01", "kbm_class": "3", "driving_experience": 10 }],
"type": "limited"
},
"engine_power": 80,
"is_taxi": False
}
我使用的方案如下:
schema = {
'engine_power': {'type': 'integer'},
'region': {'type': 'integer'},
'is_taxi': {'type': 'boolean'},
'drivers': {
'schema': {
'type': {'type': 'string'},
'data': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'birthday': {'type': 'string', 'validator': validate_age},
'kbm_class': {'type': 'string'},
'driving_experience': {'type': 'integer'}
}
}
}
}
}
}
当我得到一个错误对象时,它有太多的嵌套:
Cerberus 为每个嵌套级别创建一个列表:
{'drivers': [{'data': [{0: [{'birthday': ['driver too young']}]}]}]}
我能得到类似的东西吗:
{'drivers': {'data': [{'birthday': ['driver too young']}]}}
使用 cerberus==0.9.2
你会得到一个更简洁的错误响应,如下所示:
{'drivers': {'data': {0: {'birthday': 'driver too young'}, 3: {'birthday': 'driver too young'}}}}
您不能删除索引,因为它们对于显示列表中的哪些项目包含错误很重要。
我使用 cerberus 来验证我的数据,例如:
document = {
"region": 77,
"drivers": {
"data": [
{ "birthday": "2004-01-01", "kbm_class": "3", "driving_experience": 10 },
{ "birthday": "1988-01-01", "kbm_class": "3", "driving_experience": 10 }],
"type": "limited"
},
"engine_power": 80,
"is_taxi": False
}
我使用的方案如下:
schema = {
'engine_power': {'type': 'integer'},
'region': {'type': 'integer'},
'is_taxi': {'type': 'boolean'},
'drivers': {
'schema': {
'type': {'type': 'string'},
'data': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'birthday': {'type': 'string', 'validator': validate_age},
'kbm_class': {'type': 'string'},
'driving_experience': {'type': 'integer'}
}
}
}
}
}
}
当我得到一个错误对象时,它有太多的嵌套: Cerberus 为每个嵌套级别创建一个列表:
{'drivers': [{'data': [{0: [{'birthday': ['driver too young']}]}]}]}
我能得到类似的东西吗:
{'drivers': {'data': [{'birthday': ['driver too young']}]}}
使用 cerberus==0.9.2
你会得到一个更简洁的错误响应,如下所示:
{'drivers': {'data': {0: {'birthday': 'driver too young'}, 3: {'birthday': 'driver too young'}}}}
您不能删除索引,因为它们对于显示列表中的哪些项目包含错误很重要。