返回主题:Python Web API 框架实践

知识卡片

普通读书笔记卡 · 3462.f

未知字段可能掩盖拼写错误

理解等级:中级

在书中订单模型的默认行为下,客户端把 quantity 拼错时,服务端会把正确字段视为缺失并采用默认值 1,调用方却以为传入了数量 5。忽略未知字段会掩盖契约偏差;是否严格拒绝需按实际框架版本和模型配置核验。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 2 章《A basic API implementation》(源文件:_epub-src/OEBPS/Text/02.htm) - 结论依据:2.5 节给出客户端把 quantity 拼错为 quantit 的载荷,说明书中 FastAPI 会取默认值 1,并提出拒绝非法属性能减少集成误解。 - 原始内容:In this case, FastAPI assumes that the quantity property is missing and that the client wishes to set its value to 1 . This result could lead to confusion between the client and the server, and in such cases invalidating payloads with illegal properties helps us make the API integration more reliable.