feat: add OpenAPI error response support (issue #23)#39
Conversation
| [dependencies] | ||
| inventory = "0.3.13" | ||
| openapiv3-extended = { version = "6" } | ||
| openapiv3-extended = { git = "https://github.com/18IsabellaM/openapiv3", branch = "isabella/error_json"} |
There was a problem hiding this comment.
- Note: Using a Git branch here due to unmerged functionality in the
openapiv3repo that introduces a helper method: kurtbuilds/openapiv3#7 - Once merged upstream, this can be changed back to the released version.
There was a problem hiding this comment.
you can also use an (uncommitted) .cargo/config.toml file with the following to keep the PR mergeable:
[patch.crates-io]
openapiv3-extended = { path = "path/to/modified/local/copy" }
| http = "1.0.0" | ||
| indexmap = "2" | ||
| openapiv3-extended = { version = "6" } | ||
| openapiv3-extended = { git = "https://github.com/18IsabellaM/openapiv3", branch = "isabella/error_json"} |
There was a problem hiding this comment.
- Note: Using a Git branch here due to unmerged functionality in the
openapiv3repo that introduces a helper method: kurtbuilds/openapiv3#7 - Once merged upstream, this can be changed back to the released version.
|
Hey @kurtbuilds , I’ve opened a PR adding new functionality for error responses. When you have a chance, could you please review and consider merging it? Thanks so much! |
|
Thanks. I was fixing these merge conflicts but didn't finish last night. I'll get this over the line and published this weekend. Thank you for the contribution! IIRC, there's 1 failing test to be fixed. Welcome your help on that. |
|
Just ran |
…us codes one can match to
a49877a to
0ff7b7a
Compare
| let mut collector = ErrorCollector::default(); | ||
| collector.visit_block(&ast.block); | ||
|
|
||
| let mut errors_by_code: HashMap<String, Vec<String>> = HashMap::new(); |
There was a problem hiding this comment.
Should be BTreeMap to enforce deterministic order
|
Hi @kurtbuilds I pushed an update to change |
openapiv3crate, which I also have up for review in a separate PR. kurtbuilds/openapiv3#7PR Description:
This PR improves the OpenAPI spec generation by correctly capturing and displaying error status codes and their descriptions.
Changes made:
Updated the OpenAPI generator to automatically include error responses derived from handlers that return errors as (StatusCode, String) tuples.
Added support for grouping multiple error messages under the same status code:
Will produce the following OpenAPI response entry:
Added a new test case:
04-status_code.rsand a corresponding snapshot:04-status_code.yaml.Improved the test framework to compare parsed YAML structures instead of raw strings, preventing failures due to key ordering differences.