知识卡片

普通读书笔记卡 · 3462.e

错误路径定位缺失字段

理解等级:初级

请求体校验错误应指出字段所在路径,而不只说“参数错误”。订单示例中的 body/order/0/product 可定位到 order 数组第一项的 product。原书把这种定位类比为 JSON Pointer;实际响应中的 loc 可能是分段数组,不能把展示形式直接等同于标准指针字符串。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 2 章《A basic API implementation》(源文件:_epub-src/OEBPS/Text/02.htm) - 结论依据:2.5 节展示缺失 product 时的错误位置,并用 `body/order/0/product` 与 Python 索引对照说明如何定位嵌套字段;本卡保留示例定位用途并限定表示形式。 - 原始内容:FastAPI generates an error message that points to where in the payload the error is found. ... For example, the error message "loc: /body/order/0/product" is roughly equivalent to the following notation in Python: loc['body']['order'][0]['product'] .