Skip to content

Commit 37ceac0

Browse files
committed
[Rust] Fix error type conversion for reqwest_middleware re-exported types
When using reqwest_middleware, RequestBuilder::build() and Response methods return errors typed as reqwest_middleware::reqwest::Error (reqwest's Error re-exported through middleware). Added From impl to handle this module path. This fixes compilation errors when building with --all-features flag in middleware-enabled samples.
1 parent 4ca334e commit 37ceac0

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/rust/reqwest-trait/api_mod.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ impl<T> From<reqwest_middleware::Error> for Error<T> {
8282
}
8383
}
8484

85+
// reqwest_middleware re-exports reqwest, so we need to handle both module paths
86+
impl<T> From<reqwest_middleware::reqwest::Error> for Error<T> {
87+
fn from(e: reqwest_middleware::reqwest::Error) -> Self {
88+
Error::Reqwest(e)
89+
}
90+
}
91+
8592
{{/supportMiddleware}}
8693
impl <T> From<serde_json::Error> for Error<T> {
8794
fn from(e: serde_json::Error) -> Self {

modules/openapi-generator/src/main/resources/rust/reqwest/api_mod.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ impl<T> From<reqwest_middleware::Error> for Error<T> {
9797
}
9898
}
9999

100+
// reqwest_middleware re-exports reqwest, so we need to handle both module paths
101+
impl<T> From<reqwest_middleware::reqwest::Error> for Error<T> {
102+
fn from(e: reqwest_middleware::reqwest::Error) -> Self {
103+
Error::Reqwest(e)
104+
}
105+
}
106+
100107
{{/supportMiddleware}}
101108
impl <T> From<serde_json::Error> for Error<T> {
102109
fn from(e: serde_json::Error) -> Self {

samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ impl<T> From<reqwest_middleware::Error> for Error<T> {
5454
}
5555
}
5656

57+
// reqwest_middleware re-exports reqwest, so we need to handle both module paths
58+
impl<T> From<reqwest_middleware::reqwest::Error> for Error<T> {
59+
fn from(e: reqwest_middleware::reqwest::Error) -> Self {
60+
Error::Reqwest(e)
61+
}
62+
}
63+
5764
impl <T> From<serde_json::Error> for Error<T> {
5865
fn from(e: serde_json::Error) -> Self {
5966
Error::Serde(e)

0 commit comments

Comments
 (0)