知识卡片
未知字段可能掩盖拼写错误
在书中订单模型的默认行为下,客户端把 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.