知识卡片
错误声明给出可预期分支
在 responses 中明确列出该操作可能出现且客户端需要处理的状态,并用公共组件约束格式。把尚无特定处理的其余响应交给 default。同状态的不同业务原因可用类型或扩展字段区分。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Supporting the unhappy path: Error handling with problem+json 18.6 Adding error responses to OpenAPI · 查看原书依据
Of course, we could blindly add a default response for errors to every method and call it a day. Technically, that would cover everything and the contract would be valid. Would the contract be useful, though? If we get into the shoes
参考来源
- 位置:《Designing APIs with Swagger and OpenAPI》第18章《Supporting the unhappy path: Error handling with problem+json》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch18.htm,阅读块 145)
- 结论依据:书中比较仅写 default 与逐操作列可发生状态的接入价值。
- 原始内容:Of course, we could blindly add a default response for errors to every method and call it a day. Technically, that would cover everything and the contract would be valid. Would the contract be useful, though? If we get into the shoes