From c65363eb717a00eaa0182ecd759fe3824e1d92c4 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Mon, 15 Jun 2020 23:03:25 +0100 Subject: [PATCH] [Rust Server] Pass context to client middleware (#6574) * [Rust Server] Pass context to client middleware When creating a client with middleware, pass the context. This allows users to pass contextual data about the requests through to the client middleware. * Update samples --- .../rust-server/client-imports.mustache | 3 +- .../resources/rust-server/client-mod.mustache | 53 ++++--- .../rust-server/client-operation.mustache | 3 +- .../rust-server/server-callbacks.mustache | 46 ++++--- .../multipart-v3/.openapi-generator/FILES | 1 + .../output/multipart-v3/src/client/mod.rs | 63 ++++++--- .../no-example-v3/.openapi-generator/FILES | 1 + .../output/no-example-v3/src/client/mod.rs | 58 +++++--- .../openapi-v3/.openapi-generator/FILES | 1 + .../output/openapi-v3/src/client/mod.rs | 102 ++++++++------ .../output/openapi-v3/src/server/callbacks.rs | 53 ++++--- .../output/ops-v3/.openapi-generator/FILES | 1 + .../output/ops-v3/src/client/mod.rs | 130 ++++++++++-------- .../.openapi-generator/FILES | 1 + .../src/client/mod.rs | 127 ++++++++++------- .../rust-server-test/.openapi-generator/FILES | 1 + .../output/rust-server-test/src/client/mod.rs | 74 ++++++---- 17 files changed, 448 insertions(+), 270 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-imports.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-imports.mustache index 673a6856f43..f4a0bbd93cc 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-imports.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-imports.mustache @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; {{#apiUsesMultipartFormData}} diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache index 506cf8c8654..386c68eebc2 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache @@ -27,49 +27,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -88,14 +96,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -126,7 +136,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -156,14 +168,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -184,7 +200,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -249,12 +266,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -268,6 +286,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -313,13 +332,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache index a027811c122..641a0f5bff9 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-operation.mustache @@ -134,6 +134,7 @@ }; *request.body_mut() = Body::from(body_string); + request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(&multipart_header) { Ok(h) => h, Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e))) @@ -365,7 +366,7 @@ {{/isMapContainer}} {{/headerParams}} - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-callbacks.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-callbacks.mustache index c51299077f7..51ae0fcadd9 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-callbacks.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-callbacks.mustache @@ -17,45 +17,53 @@ use crate::{{{operationId}}}Response; {{/apiInfo}} /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client") } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -69,17 +77,20 @@ impl Client> where /// # Arguments /// /// * `connector` - Implementation of `hyper::client::Connect` to use for the client - pub fn new_with_connector(connector: C) -> Self + pub fn new_with_connector(connector: Connector) -> Self { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Self { client_service, + marker: PhantomData, } } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. pub fn new_http() -> Self { @@ -94,7 +105,8 @@ type HttpConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server. #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))] @@ -155,12 +167,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `swagger::Service` /// @@ -170,19 +183,20 @@ impl Client where ) -> Self { Client { client_service, + marker: PhantomData, } } } #[async_trait] -impl CallbackApi for Client where - C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Send + Sync, +impl CallbackApi for Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has {{#hasAuthMethods}}+ Has>{{/hasAuthMethods}} + Clone + Send + Sync, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { diff --git a/samples/server/petstore/rust-server/output/multipart-v3/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/multipart-v3/.openapi-generator/FILES index e1eb1a7a36f..93ca2d46436 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/multipart-v3/.openapi-generator/FILES @@ -1,5 +1,6 @@ .cargo/config .gitignore +.openapi-generator-ignore Cargo.toml README.md api/openapi.yaml diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs index 44319896f1e..f8a1b3204de 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; use mime::Mime; @@ -65,49 +66,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -126,14 +135,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -164,7 +175,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -194,14 +207,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -222,7 +239,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -287,12 +305,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -306,6 +325,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -351,13 +371,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -480,7 +500,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -621,6 +641,7 @@ impl Api for Client where }; *request.body_mut() = Body::from(body_string); + request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(&multipart_header) { Ok(h) => h, Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e))) @@ -632,7 +653,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -759,7 +780,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/FILES index 2334dbd1704..7e3a3959055 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/no-example-v3/.openapi-generator/FILES @@ -1,5 +1,6 @@ .cargo/config .gitignore +.openapi-generator-ignore Cargo.toml README.md api/openapi.yaml diff --git a/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs index 5948c84d2eb..c43b0ae8ad0 100644 --- a/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/no-example-v3/src/client/mod.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; @@ -58,49 +59,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -119,14 +128,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -157,7 +168,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -187,14 +200,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -215,7 +232,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -280,12 +298,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -299,6 +318,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -344,13 +364,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -411,7 +431,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES index 5033d939903..fb555b825a6 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/openapi-v3/.openapi-generator/FILES @@ -1,5 +1,6 @@ .cargo/config .gitignore +.openapi-generator-ignore Cargo.toml README.md api/openapi.yaml diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs index 46a80096974..38c1ff6b088 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/client/mod.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; @@ -82,49 +83,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -143,14 +152,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -181,7 +192,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -211,14 +224,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -239,7 +256,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -304,12 +322,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -323,6 +342,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -368,13 +388,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has + Has> + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Has> + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -425,7 +445,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -498,7 +518,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -569,7 +589,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -650,7 +670,7 @@ impl Api for Client where }, }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -719,7 +739,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -794,7 +814,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -959,7 +979,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1028,7 +1048,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1109,7 +1129,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1201,7 +1221,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1272,7 +1292,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1350,7 +1370,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1419,7 +1439,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1579,7 +1599,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1694,7 +1714,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1763,7 +1783,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1851,7 +1871,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1939,7 +1959,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2036,7 +2056,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2124,7 +2144,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2214,7 +2234,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2299,7 +2319,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2370,7 +2390,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs b/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs index 0f3ab78824a..fff50aecdfe 100644 --- a/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs +++ b/samples/server/petstore/rust-server/output/openapi-v3/src/server/callbacks.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; @@ -39,45 +40,53 @@ use crate::CallbackCallbackWithHeaderPostResponse; use crate::CallbackCallbackPostResponse; /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client") } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -91,17 +100,20 @@ impl Client> where /// # Arguments /// /// * `connector` - Implementation of `hyper::client::Connect` to use for the client - pub fn new_with_connector(connector: C) -> Self + pub fn new_with_connector(connector: Connector) -> Self { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Self { client_service, + marker: PhantomData, } } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. pub fn new_http() -> Self { @@ -116,7 +128,8 @@ type HttpConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server. #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))] @@ -177,12 +190,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `swagger::Service` /// @@ -192,19 +206,20 @@ impl Client where ) -> Self { Client { client_service, + marker: PhantomData, } } } #[async_trait] -impl CallbackApi for Client where - C: Has + Has> + Send + Sync, +impl CallbackApi for Client where S: Service< - Request, + (Request, C), Response=Response, Error=hyper::Error> + Clone + Send + Sync, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Has> + Clone + Send + Sync, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -271,7 +286,7 @@ impl CallbackApi for Client where None => {} } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -341,7 +356,7 @@ impl CallbackApi for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/samples/server/petstore/rust-server/output/ops-v3/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/ops-v3/.openapi-generator/FILES index e86946909bd..7aa723e3c57 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/ops-v3/.openapi-generator/FILES @@ -1,5 +1,6 @@ .cargo/config .gitignore +.openapi-generator-ignore Cargo.toml README.md api/openapi.yaml diff --git a/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs index 48817db8753..86c8aaa7a4a 100644 --- a/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/ops-v3/src/client/mod.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; @@ -94,49 +95,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -155,14 +164,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -193,7 +204,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -223,14 +236,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -251,7 +268,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -316,12 +334,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -335,6 +354,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -380,13 +400,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -435,7 +455,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -504,7 +524,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -573,7 +593,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -642,7 +662,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -711,7 +731,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -780,7 +800,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -849,7 +869,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -918,7 +938,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -987,7 +1007,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1056,7 +1076,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1125,7 +1145,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1194,7 +1214,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1263,7 +1283,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1332,7 +1352,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1401,7 +1421,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1470,7 +1490,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1539,7 +1559,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1608,7 +1628,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1677,7 +1697,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1746,7 +1766,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1815,7 +1835,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1884,7 +1904,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1953,7 +1973,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2022,7 +2042,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2091,7 +2111,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2160,7 +2180,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2229,7 +2249,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2298,7 +2318,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2367,7 +2387,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2436,7 +2456,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2505,7 +2525,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2574,7 +2594,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2643,7 +2663,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2712,7 +2732,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2781,7 +2801,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2850,7 +2870,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2919,7 +2939,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES index 03bc5ac3507..47093f45af6 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/.openapi-generator/FILES @@ -1,5 +1,6 @@ .cargo/config .gitignore +.openapi-generator-ignore Cargo.toml README.md api/openapi.yaml diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs index f6e3986c318..1b8f20065b4 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; use mime::Mime; @@ -95,49 +96,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -156,14 +165,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -194,7 +205,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -224,14 +237,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -252,7 +269,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -317,12 +335,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -336,6 +355,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -381,13 +401,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has + Has> + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Has> + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -448,7 +468,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -523,7 +543,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -605,7 +625,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -693,7 +713,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -781,7 +801,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -869,7 +889,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -944,7 +964,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1015,7 +1035,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1095,7 +1115,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1173,7 +1193,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1303,7 +1323,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1439,7 +1459,7 @@ impl Api for Client where None => {} } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1523,7 +1543,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1606,7 +1626,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1699,7 +1719,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1801,7 +1821,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1906,7 +1926,7 @@ impl Api for Client where None => {} } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1994,7 +2014,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2097,7 +2117,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2190,7 +2210,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2306,7 +2326,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2420,7 +2440,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2536,6 +2556,7 @@ impl Api for Client where }; *request.body_mut() = Body::from(body_string); + request.headers_mut().insert(CONTENT_TYPE, match HeaderValue::from_str(&multipart_header) { Ok(h) => h, Err(e) => return Err(ApiError(format!("Unable to create header: {} - {}", multipart_header, e))) @@ -2564,7 +2585,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2641,7 +2662,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2723,7 +2744,7 @@ impl Api for Client where } } - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2800,7 +2821,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2901,7 +2922,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -2995,7 +3016,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3073,7 +3094,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3151,7 +3172,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3222,7 +3243,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3299,7 +3320,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3393,7 +3414,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3509,7 +3530,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -3591,7 +3612,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { diff --git a/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES b/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES index 1495d4416fb..9f49d72aaaa 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES +++ b/samples/server/petstore/rust-server/output/rust-server-test/.openapi-generator/FILES @@ -1,5 +1,6 @@ .cargo/config .gitignore +.openapi-generator-ignore Cargo.toml README.md api/openapi.yaml diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs index aaece7a9b13..bbae182ce25 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs @@ -9,13 +9,14 @@ use std::io::{ErrorKind, Read}; use std::error::Error; use std::future::Future; use std::fmt; +use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; use std::str; use std::str::FromStr; use std::string::ToString; use std::task::{Context, Poll}; -use swagger::{ApiError, AuthData, BodyExt, Connector, Has, XSpanIdString}; +use swagger::{ApiError, AuthData, BodyExt, Connector, DropContextService, Has, XSpanIdString}; use url::form_urlencoded; @@ -66,49 +67,57 @@ fn into_base_path(input: impl TryInto, } /// A client that implements the API by making HTTP calls out to a server. -pub struct Client where +pub struct Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Inner service client_service: S, /// Base path of the API base_path: String, + + /// Marker + marker: PhantomData, } -impl fmt::Debug for Client where +impl fmt::Debug for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Client {{ base_path: {} }}", self.base_path) } } -impl Clone for Client where +impl Clone for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { fn clone(&self) -> Self { Self { client_service: self.client_service.clone(), base_path: self.base_path.clone(), + marker: PhantomData, } } } -impl Client> where - C: hyper::client::connect::Connect + Clone + Send + Sync + 'static +impl Client, C>, C> where + Connector: hyper::client::connect::Connect + Clone + Send + Sync + 'static, + C: Clone + Send + Sync + 'static, { /// Create a client with a custom implementation of hyper::client::Connect. /// @@ -127,14 +136,16 @@ impl Client> where pub fn try_new_with_connector( base_path: &str, protocol: Option<&'static str>, - connector: C, + connector: Connector, ) -> Result { let client_service = hyper::client::Client::builder().build(connector); + let client_service = DropContextService::new(client_service); Ok(Self { client_service, base_path: into_base_path(base_path, protocol)?, + marker: PhantomData, }) } } @@ -165,7 +176,9 @@ impl Service> for HyperClient { } } -impl Client { +impl Client, C> where + C: Clone + Send + Sync + 'static, +{ /// Create an HTTP client. /// /// # Arguments @@ -195,14 +208,18 @@ impl Client { } }; + let client_service = DropContextService::new(client_service); + Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create an HTTP client. /// @@ -223,7 +240,8 @@ type HttpsConnector = hyper_tls::HttpsConnector; #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] type HttpsConnector = hyper_openssl::HttpsConnector; -impl Client> +impl Client, C>, C> where + C: Clone + Send + Sync + 'static { /// Create a client with a TLS connection to the server /// @@ -288,12 +306,13 @@ impl Client> } } -impl Client where +impl Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Clone + Send + Sync + 'static { /// Constructor for creating a `Client` by passing in a pre-made `hyper::service::Service` / /// `tower::Service` @@ -307,6 +326,7 @@ impl Client where Ok(Self { client_service, base_path: into_base_path(base_path, None)?, + marker: PhantomData, }) } } @@ -352,13 +372,13 @@ impl Error for ClientInitError { } #[async_trait] -impl Api for Client where - C: Has + Clone + Send + Sync + 'static, +impl Api for Client where S: Service< - Request, + (Request, C), Response=Response> + Clone + Sync + Send + 'static, S::Future: Send + 'static, S::Error: Into + fmt::Display, + C: Has + Clone + Send + Sync + 'static, { fn poll_ready(&self, cx: &mut Context) -> Poll> { match self.client_service.clone().poll_ready(cx) { @@ -407,7 +427,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -482,7 +502,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -560,7 +580,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -629,7 +649,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -704,7 +724,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -788,7 +808,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -872,7 +892,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -941,7 +961,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() { @@ -1027,7 +1047,7 @@ impl Api for Client where Err(e) => return Err(ApiError(format!("Unable to create X-Span ID header value: {}", e))) }); - let mut response = client_service.call(request) + let mut response = client_service.call((request, context.clone())) .map_err(|e| ApiError(format!("No response received: {}", e))).await?; match response.status().as_u16() {