Repository navigation
feat(openapi): declare endpoint errors without Responsible - #109
Merged
Merged
Conversation
This was referenced Sep 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
当接口已经通过属性声明了全部错误响应时,
Result<Json<User>, ApiError>仍要求错误枚举实现Responsible,导致thiserror+IntoResponse的常规用法必须再维护一份错误文档。新增
#[api(errors(...))]:自动推导成功分支,错误分支完全使用接口声明。ApiError不再需要Responsible或Schematic;实际回传的 body 类型仍需Schematic,HTTP 错误处理仍由IntoResponse决定。同一个错误枚举可供不同接口声明不同错误集合。通过一个内部 trait 解析
Result的成功分支,因此支持ApiResult<T>等类型别名,无需按返回类型名称匹配或新增运行时包装。errors(...)至少声明一个响应,复用现有 response 参数解析和校验。与成功分支同状态的响应按现有合并规则处理。responses(...)继续补充/覆盖状态,不会自动免除 trait 要求;同时使用时,它在成功推导和错误合并之后生效。default全部保留;只有显式drop_default才移除 default。验证覆盖真实 HTTP 响应与文档组装、显式 body 组件收集、多个接口共用错误类型、类型别名、成功分支动态状态、属性覆盖,以及三个编译失败用例(非 Result、缺失成功 schema、旧 responses 仍要求错误契约)。解析校验和成功分支选择各有一个单元测试。
本地验证通过:gotcha 默认和 openapi 完整测试(含 README doctest)、gotcha_core all-features / no-default-features、gotcha_macro 测试、workspace all-features Clippy(-D warnings)、格式和 diff 检查。
GitHub CI:11 项检查全部通过,验证提交
8cb2434d2853adb46d9940318b1be72800c2f14c。Closes #108