-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[Rust][Client][Reqwest] Better http error handling #6481
Merged
wing328
merged 10 commits into
OpenAPITools:master
from
bcourtine:5609-rust-client-better-error-typing
Jun 13, 2020
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9e3565e
Stronger typing for http errors with Rust client. (#5609).
bcourtine 948d653
Merge branch 'master' into 5609-rust-client-better-error-typing (supp…
bcourtine ed3e8fb
Error structure can be parametrized (but is still hardcoded with `ser…
bcourtine 3ad86b3
Each API method has is own enum of functionnal errors.
bcourtine 755fc69
Fix the missing "Debug" derivation for API error enums.
bcourtine ff3d510
Generate models for error deserialization.
bcourtine 250d0ed
Handle several 2xx success models.
bcourtine a890621
Expose new API objects, required to use the API (params, success, err…
bcourtine 733fd9d
Merge remote-tracking branch 'upstream/master' into 5609-rust-client-…
bcourtine a72be48
Merge branch 'master' of https://github.com/openapitools/openapi-gene…
wing328 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
8 changes: 8 additions & 0 deletions
8
modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache
This file contains 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
This file contains 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
8 changes: 8 additions & 0 deletions
8
samples/client/petstore/rust/reqwest/fileResponseTest/src/apis/mod.rs
This file contains 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
8 changes: 8 additions & 0 deletions
8
samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
hey 🙋♂️ great attempt on this issue, but this isn't complete yet.
The openapi spec allows for defining a schema for every possible response status: eg
so instead of just checking for a success status, you'll need to match over the response status.
and deserialize based on the defined schema for that status as well as the fallback(default) schema.
I imagine this means that the return type of methods would become an enum,
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.
Hi @seunlanlege,
Thanks for your comment. I know this is just a first attempt which is incomplete.
I had the same idea of an enum as response, but I don't like it. I think we should not return
Ok
when the return status is not ok…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.
I am working on something like:
where T could be an enum of error types corresponding to error codes.
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.
also bear in mind that there could be more than one success response in the
2xx
range, So success types would potentially be an enumThere 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.
With an enum, multiple success codes can be handled, but this case is not frequent. So I don't know if it is worth complicating the generated code for this.
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.
unfortunately it's actually very common 😅
jira/sendgrid's openapi specifications have multiple 2xx success schemas