知识卡片
按状态码描述响应
OpenAPI 操作的 responses 把每种响应状态码作为键,再写说明、媒体类型和载荷模式。即便同一路径下有多个方法,每个方法仍需声明自身的成功与错误结果,调用方才能按状态码解释返回内容。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 5 章《Documenting REST APIs with OpenAPI》(源文件:_epub-src/OEBPS/Text/05.htm)
- 结论依据:原文用 GET 订单响应示例明确 status code、description、content、schema 的层次,并指出除 200 外还可列错误响应。
- 原始内容:We define the endpoint’s responses as objects in which the key is the response’s status code, such as 200. We also describe the response’s content type and its schema, GetOrderSchema . ... In this case, we only provide the specification for the 200 (OK) successful response, but we can also document other status codes, such as error responses.