-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add OpenAPI error response support (issue #23) #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
core/Cargo.toml
Outdated
| [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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kurtbuilds fixed it
oasgen/Cargo.toml
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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
macro/src/lib.rs
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.