eve 0.8 `allow_unknown` 在嵌套的字典字段中

eve 0.8 `allow_unknown` in nested dict field

我们使用 Eve 0.7 开发了一个 API,它使用了 allow_unknown on a nested dict field。根据 cerberus 文档,该字段按预期工作。

我们现在升级到 Eve 0.8,我们的端点不再遵守嵌套字典中的 allow_unknown 参数。

例子

settings.py

DOMAIN = {
    'endpoint': {
        'schema': {
            'data': {
                'type': 'dict',
                'allow_unknown': True,
                'schema': {
                    'prop': {'type': 'string'}
                }
            }
        }
    }
}

RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']

app.py

from eve import Eve

app = Eve()
app.run(debug=True)

测试

通过

$ curl -d '{"data": {"prop": "test prop"}}' -H 'Content-Type: application/json'  http://127.0.0.1:5000/endpoint
{"_updated": "Fri, 08 Jun 2018 19:43:11 GMT", "_created": "Fri, 08 Jun 2018 19:43:11 GMT", "_etag": "e04dd19a6e13c74ccdb5561722bb001b0f5dff28", "_id": "5b1adc4f198a2527650320a4", "_links": {"self": {"title": "Endpoint", "href": "endpoint/5b1adc4f198a2527650320a4"}}, "_status": "OK"}

失败(本应通过)

$ curl -d '{"data": {"prop": "test prop", "test": 2}}' -H 'Content-Type: application/json'  http://127.0.0.1:5000/endpoint
{"_status": "ERR", "_issues": {"data": {"test": "unknown field"}}, "_error": {"code": 422, "message": "Insertion failure: 1 document(s) contain(s) error(s)"}}

这是一个实际问题,感谢您报告。它已通过 v0.8.1.dev0 修复。

感谢您的举报!