diff --git a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache index 53c02a6f286..f8da736d432 100644 --- a/modules/openapi-generator/src/main/resources/rust/Cargo.mustache +++ b/modules/openapi-generator/src/main/resources/rust/Cargo.mustache @@ -10,10 +10,12 @@ serde_derive = "^1.0" serde_json = "^1.0" url = "^2.2" {{#hyper}} -hyper = "~0.11" +hyper = { version = "~0.14", features = ["full"] } +hyper-tls = "~0.5" +http = "~0.2" serde_yaml = "0.7" base64 = "~0.7.0" -futures = "0.1.23" +futures = "^0.3" {{/hyper}} {{#reqwest}} {{^supportAsync}} diff --git a/modules/openapi-generator/src/main/resources/rust/hyper/api.mustache b/modules/openapi-generator/src/main/resources/rust/hyper/api.mustache index e2833f16ed9..a055014fb5c 100644 --- a/modules/openapi-generator/src/main/resources/rust/hyper/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/hyper/api.mustache @@ -1,21 +1,23 @@ {{>partial_header}} use std::rc::Rc; use std::borrow::Borrow; +use std::pin::Pin; #[allow(unused_imports)] use std::option::Option; use hyper; -use serde_json; use futures::Future; use super::{Error, configuration}; use super::request as __internal_request; -pub struct {{{classname}}}Client { +pub struct {{{classname}}}Client + where C: Clone + std::marker::Send + Sync + 'static { configuration: Rc>, } -impl {{{classname}}}Client { +impl {{{classname}}}Client + where C: Clone + std::marker::Send + Sync { pub fn new(configuration: Rc>) -> {{{classname}}}Client { {{{classname}}}Client { configuration, @@ -26,16 +28,18 @@ impl {{{classname}}}Client { pub trait {{{classname}}} { {{#operations}} {{#operation}} - fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Box>>; + fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Pin>>>; {{/operation}} {{/operations}} } -impl{{{classname}}} for {{{classname}}}Client { -{{#operations}} -{{#operation}} - fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{^isUuid}}&str{{/isUuid}}{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::{{{httpMethod}}}, "{{{path}}}".to_string()) +impl{{{classname}}} for {{{classname}}}Client + where C: Clone + std::marker::Send + Sync { + {{#operations}} + {{#operation}} + #[allow(unused_mut)] + fn {{{operationId}}}(&self, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}crate::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::{{{httpMethod.toUpperCase}}}, "{{{path}}}".to_string()) {{#hasAuthMethods}} {{#authMethods}} {{#isApiKey}} @@ -68,7 +72,8 @@ impl{{{classname}}} for {{{classname}}}Client { {{/required}} {{^required}} if let Some(ref s) = {{{paramName}}} { - req = req.with_query_param("{{{baseName}}}".to_string(), s{{#isArray}}.join(","){{/isArray}}.to_string()); + let query_value = {{#isArray}}s.iter().map(|s| s.to_string()).collect::>().join(","){{/isArray}}{{^isArray}}s.to_string(){{/isArray}}; + req = req.with_query_param("{{{baseName}}}".to_string(), query_value); } {{/required}} {{/queryParams}} diff --git a/modules/openapi-generator/src/main/resources/rust/hyper/api_mod.mustache b/modules/openapi-generator/src/main/resources/rust/hyper/api_mod.mustache index 4f220c93d56..8314cb60b07 100644 --- a/modules/openapi-generator/src/main/resources/rust/hyper/api_mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust/hyper/api_mod.mustache @@ -1,49 +1,45 @@ +use http; use hyper; -use serde; use serde_json; #[derive(Debug)] -pub enum Error { - UriError(hyper::error::UriError), +pub enum Error { + Api(ApiError), + Header(hyper::http::header::InvalidHeaderValue), + Http(http::Error), Hyper(hyper::Error), Serde(serde_json::Error), - ApiError(ApiError), + UriError(http::uri::InvalidUri), } #[derive(Debug)] -pub struct ApiError { +pub struct ApiError { pub code: hyper::StatusCode, - pub content: Option, + pub body: hyper::body::Body, } -impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error - where T: serde::Deserialize<'de> { - fn from(e: (hyper::StatusCode, &'de [u8])) -> Self { - if e.1.len() == 0 { - return Error::ApiError(ApiError{ - code: e.0, - content: None, - }); - } - match serde_json::from_slice::(e.1) { - Ok(t) => Error::ApiError(ApiError{ - code: e.0, - content: Some(t), - }), - Err(e) => { - Error::from(e) - } - } +impl From<(hyper::StatusCode, hyper::body::Body)> for Error { + fn from(e: (hyper::StatusCode, hyper::body::Body)) -> Self { + Error::Api(ApiError { + code: e.0, + body: e.1, + }) } } -impl From for Error { +impl From for Error { + fn from(e: http::Error) -> Self { + return Error::Http(e) + } +} + +impl From for Error { fn from(e: hyper::Error) -> Self { return Error::Hyper(e) } } -impl From for Error { +impl From for Error { fn from(e: serde_json::Error) -> Self { return Error::Serde(e) } diff --git a/modules/openapi-generator/src/main/resources/rust/hyper/client.mustache b/modules/openapi-generator/src/main/resources/rust/hyper/client.mustache index 5b3bcf85c75..25124d94b36 100644 --- a/modules/openapi-generator/src/main/resources/rust/hyper/client.mustache +++ b/modules/openapi-generator/src/main/resources/rust/hyper/client.mustache @@ -18,7 +18,8 @@ pub struct APIClient { } impl APIClient { - pub fn new(configuration: Configuration) -> APIClient { + pub fn new(configuration: Configuration) -> APIClient + where C: Clone + std::marker::Send + Sync + 'static { let rc = Rc::new(configuration); APIClient { diff --git a/modules/openapi-generator/src/main/resources/rust/hyper/configuration.mustache b/modules/openapi-generator/src/main/resources/rust/hyper/configuration.mustache index adb51d6e92c..ee6f407d31b 100644 --- a/modules/openapi-generator/src/main/resources/rust/hyper/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/rust/hyper/configuration.mustache @@ -1,7 +1,8 @@ {{>partial_header}} use hyper; -pub struct Configuration { +pub struct Configuration + where C: Clone + std::marker::Send + Sync + 'static { pub base_path: String, pub user_agent: Option, pub client: hyper::client::Client, @@ -18,12 +19,13 @@ pub struct ApiKey { pub key: String, } -impl Configuration { +impl Configuration + where C: Clone + std::marker::Send + Sync { pub fn new(client: hyper::client::Client) -> Configuration { Configuration { base_path: "{{{basePath}}}".to_owned(), user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}Some("OpenAPI-Generator/{{{version}}}/rust".to_owned()){{/httpUserAgent}}, - client: client, + client, basic_auth: None, oauth_access_token: None, api_key: None, diff --git a/modules/openapi-generator/src/main/resources/rust/request.rs b/modules/openapi-generator/src/main/resources/rust/request.rs index f97b5277196..0aa51fa0c59 100644 --- a/modules/openapi-generator/src/main/resources/rust/request.rs +++ b/modules/openapi-generator/src/main/resources/rust/request.rs @@ -1,14 +1,16 @@ -use std::borrow::Cow; use std::collections::HashMap; +use std::pin::Pin; -use super::{configuration, Error}; use futures; -use futures::{Future, Stream}; +use futures::Future; +use futures::future::*; use hyper; -use hyper::header::UserAgent; +use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HeaderValue, USER_AGENT}; use serde; use serde_json; +use super::{configuration, Error}; + pub(crate) struct ApiKey { pub in_header: bool, pub in_query: bool, @@ -32,8 +34,11 @@ pub(crate) enum Auth { Oauth, } +/// If the authorization type is unspecified then it will be automatically detected based +/// on the configuration. This functionality is useful when the OpenAPI definition does not +/// include an authorization scheme. pub(crate) struct Request { - auth: Auth, + auth: Option, method: hyper::Method, path: String, query_params: HashMap, @@ -48,9 +53,9 @@ pub(crate) struct Request { impl Request { pub fn new(method: hyper::Method, path: String) -> Self { Request { - auth: Auth::None, - method: method, - path: path, + auth: None, + method, + path, query_params: HashMap::new(), path_params: HashMap::new(), form_params: HashMap::new(), @@ -91,24 +96,20 @@ impl Request { } pub fn with_auth(mut self, auth: Auth) -> Self { - self.auth = auth; + self.auth = Some(auth); self } pub fn execute<'a, C, U>( self, conf: &configuration::Configuration, - ) -> Box> + 'a> - where - C: hyper::client::Connect, - U: Sized + 'a, - for<'de> U: serde::Deserialize<'de>, + ) -> Pin> + 'a>> + where + C: hyper::client::connect::Connect + Clone + std::marker::Send + Sync, + U: Sized + std::marker::Send + 'a, + for<'de> U: serde::Deserialize<'de>, { let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned()); - // raw_headers is for headers we don't know the proper type of (e.g. custom api key - // headers); headers is for ones we do know the type of. - let mut raw_headers = HashMap::new(); - let mut headers: hyper::header::Headers = hyper::header::Headers::new(); let mut path = self.path; for (k, v) in self.path_params { @@ -116,46 +117,10 @@ impl Request { path = path.replace(&format!("{{{}}}", k), &v); } - for (k, v) in self.header_params { - raw_headers.insert(k, v); - } - for (key, val) in self.query_params { query_string.append_pair(&key, &val); } - match self.auth { - Auth::ApiKey(apikey) => { - if let Some(ref key) = conf.api_key { - let val = apikey.key(&key.prefix, &key.key); - if apikey.in_query { - query_string.append_pair(&apikey.param_name, &val); - } - if apikey.in_header { - raw_headers.insert(apikey.param_name, val); - } - } - } - Auth::Basic => { - if let Some(ref auth_conf) = conf.basic_auth { - let auth = hyper::header::Authorization(hyper::header::Basic { - username: auth_conf.0.to_owned(), - password: auth_conf.1.to_owned(), - }); - headers.set(auth); - } - } - Auth::Oauth => { - if let Some(ref token) = conf.oauth_access_token { - let auth = hyper::header::Authorization(hyper::header::Bearer { - token: token.to_owned(), - }); - headers.set(auth); - } - } - Auth::None => {} - } - let mut uri_str = format!("{}{}", conf.base_path, path); let query_string_str = query_string.finish(); @@ -164,76 +129,110 @@ impl Request { uri_str += &query_string_str; } let uri: hyper::Uri = match uri_str.parse() { - Err(e) => { - return Box::new(futures::future::err(Error::UriError(e))); - } + Err(e) => return Box::pin(futures::future::err(Error::UriError(e))), Ok(u) => u, }; - let mut req = hyper::Request::new(self.method, uri); - { - let req_headers = req.headers_mut(); - if let Some(ref user_agent) = conf.user_agent { - req_headers.set(UserAgent::new(Cow::Owned(user_agent.clone()))); - } + let mut req_builder = hyper::Request::builder() + .uri(uri) + .method(self.method); - req_headers.extend(headers.iter()); - - for (key, val) in raw_headers { - req_headers.set_raw(key, val); + // Detect the authorization type if it hasn't been set. + let auth = self.auth.unwrap_or_else(|| + if conf.api_key.is_some() { + panic!("Cannot automatically set the API key from the configuration, it must be specified in the OpenAPI definition") + } else if conf.oauth_access_token.is_some() { + Auth::Oauth + } else if conf.basic_auth.is_some() { + Auth::Basic + } else { + Auth::None } + ); + match auth { + Auth::ApiKey(apikey) => { + if let Some(ref key) = conf.api_key { + let val = apikey.key(&key.prefix, &key.key); + if apikey.in_query { + query_string.append_pair(&apikey.param_name, &val); + } + if apikey.in_header { + req_builder = req_builder.header(&apikey.param_name, val); + } + } + } + Auth::Basic => { + if let Some(ref auth_conf) = conf.basic_auth { + let mut text = auth_conf.0.clone(); + text.push(':'); + if let Some(ref pass) = auth_conf.1 { + text.push_str(&pass[..]); + } + let encoded = base64::encode(&text); + req_builder = req_builder.header(AUTHORIZATION, encoded); + } + } + Auth::Oauth => { + if let Some(ref token) = conf.oauth_access_token { + let text = "Bearer ".to_owned() + token; + req_builder = req_builder.header(AUTHORIZATION, text); + } + } + Auth::None => {} } - if self.form_params.len() > 0 { - req.headers_mut().set(hyper::header::ContentType::form_url_encoded()); + if let Some(ref user_agent) = conf.user_agent { + req_builder = req_builder.header(USER_AGENT, match HeaderValue::from_str(user_agent) { + Ok(header_value) => header_value, + Err(e) => return Box::pin(futures::future::err(super::Error::Header(e))) + }); + } + + for (k, v) in self.header_params { + req_builder = req_builder.header(&k, v); + } + + let req_headers = req_builder.headers_mut().unwrap(); + let request_result = if self.form_params.len() > 0 { + req_headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/ x-www-form-urlencoded")); let mut enc = ::url::form_urlencoded::Serializer::new("".to_owned()); for (k, v) in self.form_params { enc.append_pair(&k, &v); } - req.set_body(enc.finish()); - } + req_builder.body(hyper::Body::from(enc.finish())) + } else if let Some(body) = self.serialized_body { + req_headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); + req_headers.insert(CONTENT_LENGTH, body.len().into()); + req_builder.body(hyper::Body::from(body)) + } else { + req_builder.body(hyper::Body::default()) + }; + let request = match request_result { + Ok(request) => request, + Err(e) => return Box::pin(futures::future::err(Error::from(e))) + }; - if let Some(body) = self.serialized_body { - req.headers_mut().set(hyper::header::ContentType::json()); - req.headers_mut() - .set(hyper::header::ContentLength(body.len() as u64)); - req.set_body(body); - } - - let no_ret_type = self.no_return_type; - let res = conf.client - .request(req) - .map_err(|e| Error::from(e)) - .and_then(|resp| { - let status = resp.status(); - resp.body() - .concat2() - .and_then(move |body| Ok((status, body))) - .map_err(|e| Error::from(e)) - }) - .and_then(|(status, body)| { - if status.is_success() { - Ok(body) - } else { - Err(Error::from((status, &*body))) - } - }); - Box::new( - res - .and_then(move |body| { - let parsed: Result = if no_ret_type { - // This is a hack; if there's no_ret_type, U is (), but serde_json gives an - // error when deserializing "" into (), so deserialize 'null' into it - // instead. - // An alternate option would be to require U: Default, and then return - // U::default() here instead since () implements that, but then we'd - // need to impl default for all models. - serde_json::from_str("null") - } else { - serde_json::from_slice(&body) - }; - parsed.map_err(|e| Error::from(e)) - }) - ) + let no_return_type = self.no_return_type; + Box::pin(conf.client + .request(request) + .map_err(|e| Error::from(e)) + .and_then(move |response| { + let status = response.status(); + if !status.is_success() { + futures::future::err::(Error::from((status, response.into_body()))).boxed() + } else if no_return_type { + // This is a hack; if there's no_ret_type, U is (), but serde_json gives an + // error when deserializing "" into (), so deserialize 'null' into it + // instead. + // An alternate option would be to require U: Default, and then return + // U::default() here instead since () implements that, but then we'd + // need to impl default for all models. + futures::future::ok::(serde_json::from_str("null").expect("serde null value")).boxed() + } else { + hyper::body::to_bytes(response.into_body()) + .map(|bytes| serde_json::from_slice(&bytes.unwrap())) + .map_err(|e| Error::from(e)).boxed() + } + })) } } diff --git a/samples/client/petstore/rust/hyper/petstore/Cargo.toml b/samples/client/petstore/rust/hyper/petstore/Cargo.toml index 4bed4953a55..443de5b186a 100644 --- a/samples/client/petstore/rust/hyper/petstore/Cargo.toml +++ b/samples/client/petstore/rust/hyper/petstore/Cargo.toml @@ -9,10 +9,12 @@ serde = "^1.0" serde_derive = "^1.0" serde_json = "^1.0" url = "^2.2" -hyper = "~0.11" +hyper = { version = "~0.14", features = ["full"] } +hyper-tls = "~0.5" +http = "~0.2" serde_yaml = "0.7" base64 = "~0.7.0" -futures = "0.1.23" +futures = "^0.3" [dev-dependencies] tokio-core = "*" diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs index 34953d4a063..290b99e86f3 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/client.rs @@ -10,7 +10,8 @@ pub struct APIClient { } impl APIClient { - pub fn new(configuration: Configuration) -> APIClient { + pub fn new(configuration: Configuration) -> APIClient + where C: Clone + std::marker::Send + Sync + 'static { let rc = Rc::new(configuration); APIClient { diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/configuration.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/configuration.rs index 83d5f1c3d0c..ae41a752976 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/configuration.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/configuration.rs @@ -10,7 +10,8 @@ use hyper; -pub struct Configuration { +pub struct Configuration + where C: Clone + std::marker::Send + Sync + 'static { pub base_path: String, pub user_agent: Option, pub client: hyper::client::Client, @@ -27,12 +28,13 @@ pub struct ApiKey { pub key: String, } -impl Configuration { +impl Configuration + where C: Clone + std::marker::Send + Sync { pub fn new(client: hyper::client::Client) -> Configuration { Configuration { base_path: "http://petstore.swagger.io/v2".to_owned(), user_agent: Some("OpenAPI-Generator/1.0.0/rust".to_owned()), - client: client, + client, basic_auth: None, oauth_access_token: None, api_key: None, diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs index c9d96c29fd0..1245257e5d8 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/mod.rs @@ -1,49 +1,45 @@ +use http; use hyper; -use serde; use serde_json; #[derive(Debug)] -pub enum Error { - UriError(hyper::error::UriError), +pub enum Error { + Api(ApiError), + Header(hyper::http::header::InvalidHeaderValue), + Http(http::Error), Hyper(hyper::Error), Serde(serde_json::Error), - ApiError(ApiError), + UriError(http::uri::InvalidUri), } #[derive(Debug)] -pub struct ApiError { +pub struct ApiError { pub code: hyper::StatusCode, - pub content: Option, + pub body: hyper::body::Body, } -impl<'de, T> From<(hyper::StatusCode, &'de [u8])> for Error - where T: serde::Deserialize<'de> { - fn from(e: (hyper::StatusCode, &'de [u8])) -> Self { - if e.1.len() == 0 { - return Error::ApiError(ApiError{ - code: e.0, - content: None, - }); - } - match serde_json::from_slice::(e.1) { - Ok(t) => Error::ApiError(ApiError{ - code: e.0, - content: Some(t), - }), - Err(e) => { - Error::from(e) - } - } +impl From<(hyper::StatusCode, hyper::body::Body)> for Error { + fn from(e: (hyper::StatusCode, hyper::body::Body)) -> Self { + Error::Api(ApiError { + code: e.0, + body: e.1, + }) } } -impl From for Error { +impl From for Error { + fn from(e: http::Error) -> Self { + return Error::Http(e) + } +} + +impl From for Error { fn from(e: hyper::Error) -> Self { return Error::Hyper(e) } } -impl From for Error { +impl From for Error { fn from(e: serde_json::Error) -> Self { return Error::Serde(e) } diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/pet_api.rs index f1bdaf0e89a..3d90eae36b3 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/pet_api.rs @@ -4,27 +4,29 @@ * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * The version of the OpenAPI document: 1.0.0 - * + * * Generated by: https://openapi-generator.tech */ use std::rc::Rc; use std::borrow::Borrow; +use std::pin::Pin; #[allow(unused_imports)] use std::option::Option; use hyper; -use serde_json; use futures::Future; use super::{Error, configuration}; use super::request as __internal_request; -pub struct PetApiClient { +pub struct PetApiClient + where C: Clone + std::marker::Send + Sync + 'static { configuration: Rc>, } -impl PetApiClient { +impl PetApiClient + where C: Clone + std::marker::Send + Sync { pub fn new(configuration: Rc>) -> PetApiClient { PetApiClient { configuration, @@ -33,19 +35,21 @@ impl PetApiClient { } pub trait PetApi { - fn add_pet(&self, pet: crate::models::Pet) -> Box>>; - fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box>>; - fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>>; - fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>>; - fn get_pet_by_id(&self, pet_id: i64) -> Box>>; - fn update_pet(&self, pet: crate::models::Pet) -> Box>>; - fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box>>; - fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box>>; + fn add_pet(&self, body: crate::models::Pet) -> Pin>>>; + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Pin>>>; + fn find_pets_by_status(&self, status: Vec) -> Pin, Error>>>>; + fn find_pets_by_tags(&self, tags: Vec) -> Pin, Error>>>>; + fn get_pet_by_id(&self, pet_id: i64) -> Pin>>>; + fn update_pet(&self, body: crate::models::Pet) -> Pin>>>; + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Pin>>>; + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Pin>>>; } -implPetApi for PetApiClient { - fn add_pet(&self, pet: crate::models::Pet) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/pet".to_string()) +implPetApi for PetApiClient + where C: Clone + std::marker::Send + Sync { + #[allow(unused_mut)] + fn add_pet(&self, body: crate::models::Pet) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/pet".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_body_param(pet); @@ -53,8 +57,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Delete, "/pet/{petId}".to_string()) + #[allow(unused_mut)] + fn delete_pet(&self, pet_id: i64, api_key: Option<&str>) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::DELETE, "/pet/{petId}".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_path_param("petId".to_string(), pet_id.to_string()); @@ -66,8 +71,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/pet/findByStatus".to_string()) + #[allow(unused_mut)] + fn find_pets_by_status(&self, status: Vec) -> Pin, Error>>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/pet/findByStatus".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_query_param("status".to_string(), status.join(",").to_string()); @@ -75,8 +81,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/pet/findByTags".to_string()) + #[allow(unused_mut)] + fn find_pets_by_tags(&self, tags: Vec) -> Pin, Error>>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/pet/findByTags".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_query_param("tags".to_string(), tags.join(",").to_string()); @@ -84,8 +91,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn get_pet_by_id(&self, pet_id: i64) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/pet/{petId}".to_string()) + #[allow(unused_mut)] + fn get_pet_by_id(&self, pet_id: i64) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/pet/{petId}".to_string()) .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ in_header: true, in_query: false, @@ -97,8 +105,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn update_pet(&self, pet: crate::models::Pet) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Put, "/pet".to_string()) + #[allow(unused_mut)] + fn update_pet(&self, body: crate::models::Pet) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::PUT, "/pet".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_body_param(pet); @@ -106,8 +115,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/pet/{petId}".to_string()) + #[allow(unused_mut)] + fn update_pet_with_form(&self, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/pet/{petId}".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_path_param("petId".to_string(), pet_id.to_string()); @@ -122,8 +132,9 @@ implPetApi for PetApiClient { req.execute(self.configuration.borrow()) } - fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/pet/{petId}/uploadImage".to_string()) + #[allow(unused_mut)] + fn upload_file(&self, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/pet/{petId}/uploadImage".to_string()) .with_auth(__internal_request::Auth::Oauth) ; req = req.with_path_param("petId".to_string(), pet_id.to_string()); diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/request.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/request.rs index f97b5277196..0aa51fa0c59 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/request.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/request.rs @@ -1,14 +1,16 @@ -use std::borrow::Cow; use std::collections::HashMap; +use std::pin::Pin; -use super::{configuration, Error}; use futures; -use futures::{Future, Stream}; +use futures::Future; +use futures::future::*; use hyper; -use hyper::header::UserAgent; +use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, HeaderValue, USER_AGENT}; use serde; use serde_json; +use super::{configuration, Error}; + pub(crate) struct ApiKey { pub in_header: bool, pub in_query: bool, @@ -32,8 +34,11 @@ pub(crate) enum Auth { Oauth, } +/// If the authorization type is unspecified then it will be automatically detected based +/// on the configuration. This functionality is useful when the OpenAPI definition does not +/// include an authorization scheme. pub(crate) struct Request { - auth: Auth, + auth: Option, method: hyper::Method, path: String, query_params: HashMap, @@ -48,9 +53,9 @@ pub(crate) struct Request { impl Request { pub fn new(method: hyper::Method, path: String) -> Self { Request { - auth: Auth::None, - method: method, - path: path, + auth: None, + method, + path, query_params: HashMap::new(), path_params: HashMap::new(), form_params: HashMap::new(), @@ -91,24 +96,20 @@ impl Request { } pub fn with_auth(mut self, auth: Auth) -> Self { - self.auth = auth; + self.auth = Some(auth); self } pub fn execute<'a, C, U>( self, conf: &configuration::Configuration, - ) -> Box> + 'a> - where - C: hyper::client::Connect, - U: Sized + 'a, - for<'de> U: serde::Deserialize<'de>, + ) -> Pin> + 'a>> + where + C: hyper::client::connect::Connect + Clone + std::marker::Send + Sync, + U: Sized + std::marker::Send + 'a, + for<'de> U: serde::Deserialize<'de>, { let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned()); - // raw_headers is for headers we don't know the proper type of (e.g. custom api key - // headers); headers is for ones we do know the type of. - let mut raw_headers = HashMap::new(); - let mut headers: hyper::header::Headers = hyper::header::Headers::new(); let mut path = self.path; for (k, v) in self.path_params { @@ -116,46 +117,10 @@ impl Request { path = path.replace(&format!("{{{}}}", k), &v); } - for (k, v) in self.header_params { - raw_headers.insert(k, v); - } - for (key, val) in self.query_params { query_string.append_pair(&key, &val); } - match self.auth { - Auth::ApiKey(apikey) => { - if let Some(ref key) = conf.api_key { - let val = apikey.key(&key.prefix, &key.key); - if apikey.in_query { - query_string.append_pair(&apikey.param_name, &val); - } - if apikey.in_header { - raw_headers.insert(apikey.param_name, val); - } - } - } - Auth::Basic => { - if let Some(ref auth_conf) = conf.basic_auth { - let auth = hyper::header::Authorization(hyper::header::Basic { - username: auth_conf.0.to_owned(), - password: auth_conf.1.to_owned(), - }); - headers.set(auth); - } - } - Auth::Oauth => { - if let Some(ref token) = conf.oauth_access_token { - let auth = hyper::header::Authorization(hyper::header::Bearer { - token: token.to_owned(), - }); - headers.set(auth); - } - } - Auth::None => {} - } - let mut uri_str = format!("{}{}", conf.base_path, path); let query_string_str = query_string.finish(); @@ -164,76 +129,110 @@ impl Request { uri_str += &query_string_str; } let uri: hyper::Uri = match uri_str.parse() { - Err(e) => { - return Box::new(futures::future::err(Error::UriError(e))); - } + Err(e) => return Box::pin(futures::future::err(Error::UriError(e))), Ok(u) => u, }; - let mut req = hyper::Request::new(self.method, uri); - { - let req_headers = req.headers_mut(); - if let Some(ref user_agent) = conf.user_agent { - req_headers.set(UserAgent::new(Cow::Owned(user_agent.clone()))); - } + let mut req_builder = hyper::Request::builder() + .uri(uri) + .method(self.method); - req_headers.extend(headers.iter()); - - for (key, val) in raw_headers { - req_headers.set_raw(key, val); + // Detect the authorization type if it hasn't been set. + let auth = self.auth.unwrap_or_else(|| + if conf.api_key.is_some() { + panic!("Cannot automatically set the API key from the configuration, it must be specified in the OpenAPI definition") + } else if conf.oauth_access_token.is_some() { + Auth::Oauth + } else if conf.basic_auth.is_some() { + Auth::Basic + } else { + Auth::None } + ); + match auth { + Auth::ApiKey(apikey) => { + if let Some(ref key) = conf.api_key { + let val = apikey.key(&key.prefix, &key.key); + if apikey.in_query { + query_string.append_pair(&apikey.param_name, &val); + } + if apikey.in_header { + req_builder = req_builder.header(&apikey.param_name, val); + } + } + } + Auth::Basic => { + if let Some(ref auth_conf) = conf.basic_auth { + let mut text = auth_conf.0.clone(); + text.push(':'); + if let Some(ref pass) = auth_conf.1 { + text.push_str(&pass[..]); + } + let encoded = base64::encode(&text); + req_builder = req_builder.header(AUTHORIZATION, encoded); + } + } + Auth::Oauth => { + if let Some(ref token) = conf.oauth_access_token { + let text = "Bearer ".to_owned() + token; + req_builder = req_builder.header(AUTHORIZATION, text); + } + } + Auth::None => {} } - if self.form_params.len() > 0 { - req.headers_mut().set(hyper::header::ContentType::form_url_encoded()); + if let Some(ref user_agent) = conf.user_agent { + req_builder = req_builder.header(USER_AGENT, match HeaderValue::from_str(user_agent) { + Ok(header_value) => header_value, + Err(e) => return Box::pin(futures::future::err(super::Error::Header(e))) + }); + } + + for (k, v) in self.header_params { + req_builder = req_builder.header(&k, v); + } + + let req_headers = req_builder.headers_mut().unwrap(); + let request_result = if self.form_params.len() > 0 { + req_headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/ x-www-form-urlencoded")); let mut enc = ::url::form_urlencoded::Serializer::new("".to_owned()); for (k, v) in self.form_params { enc.append_pair(&k, &v); } - req.set_body(enc.finish()); - } + req_builder.body(hyper::Body::from(enc.finish())) + } else if let Some(body) = self.serialized_body { + req_headers.insert(CONTENT_TYPE, HeaderValue::from_static("application/json")); + req_headers.insert(CONTENT_LENGTH, body.len().into()); + req_builder.body(hyper::Body::from(body)) + } else { + req_builder.body(hyper::Body::default()) + }; + let request = match request_result { + Ok(request) => request, + Err(e) => return Box::pin(futures::future::err(Error::from(e))) + }; - if let Some(body) = self.serialized_body { - req.headers_mut().set(hyper::header::ContentType::json()); - req.headers_mut() - .set(hyper::header::ContentLength(body.len() as u64)); - req.set_body(body); - } - - let no_ret_type = self.no_return_type; - let res = conf.client - .request(req) - .map_err(|e| Error::from(e)) - .and_then(|resp| { - let status = resp.status(); - resp.body() - .concat2() - .and_then(move |body| Ok((status, body))) - .map_err(|e| Error::from(e)) - }) - .and_then(|(status, body)| { - if status.is_success() { - Ok(body) - } else { - Err(Error::from((status, &*body))) - } - }); - Box::new( - res - .and_then(move |body| { - let parsed: Result = if no_ret_type { - // This is a hack; if there's no_ret_type, U is (), but serde_json gives an - // error when deserializing "" into (), so deserialize 'null' into it - // instead. - // An alternate option would be to require U: Default, and then return - // U::default() here instead since () implements that, but then we'd - // need to impl default for all models. - serde_json::from_str("null") - } else { - serde_json::from_slice(&body) - }; - parsed.map_err(|e| Error::from(e)) - }) - ) + let no_return_type = self.no_return_type; + Box::pin(conf.client + .request(request) + .map_err(|e| Error::from(e)) + .and_then(move |response| { + let status = response.status(); + if !status.is_success() { + futures::future::err::(Error::from((status, response.into_body()))).boxed() + } else if no_return_type { + // This is a hack; if there's no_ret_type, U is (), but serde_json gives an + // error when deserializing "" into (), so deserialize 'null' into it + // instead. + // An alternate option would be to require U: Default, and then return + // U::default() here instead since () implements that, but then we'd + // need to impl default for all models. + futures::future::ok::(serde_json::from_str("null").expect("serde null value")).boxed() + } else { + hyper::body::to_bytes(response.into_body()) + .map(|bytes| serde_json::from_slice(&bytes.unwrap())) + .map_err(|e| Error::from(e)).boxed() + } + })) } } diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/store_api.rs index 7e5aaa33da2..303a418d696 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/store_api.rs @@ -4,27 +4,29 @@ * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * The version of the OpenAPI document: 1.0.0 - * + * * Generated by: https://openapi-generator.tech */ use std::rc::Rc; use std::borrow::Borrow; +use std::pin::Pin; #[allow(unused_imports)] use std::option::Option; use hyper; -use serde_json; use futures::Future; use super::{Error, configuration}; use super::request as __internal_request; -pub struct StoreApiClient { +pub struct StoreApiClient + where C: Clone + std::marker::Send + Sync + 'static { configuration: Rc>, } -impl StoreApiClient { +impl StoreApiClient + where C: Clone + std::marker::Send + Sync { pub fn new(configuration: Rc>) -> StoreApiClient { StoreApiClient { configuration, @@ -33,15 +35,17 @@ impl StoreApiClient { } pub trait StoreApi { - fn delete_order(&self, order_id: &str) -> Box>>; - fn get_inventory(&self, ) -> Box, Error = Error>>; - fn get_order_by_id(&self, order_id: i64) -> Box>>; - fn place_order(&self, order: crate::models::Order) -> Box>>; + fn delete_order(&self, order_id: &str) -> Pin>>>; + fn get_inventory(&self, ) -> Pin, Error>>>>; + fn get_order_by_id(&self, order_id: i64) -> Pin>>>; + fn place_order(&self, body: crate::models::Order) -> Pin>>>; } -implStoreApi for StoreApiClient { - fn delete_order(&self, order_id: &str) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Delete, "/store/order/{orderId}".to_string()) +implStoreApi for StoreApiClient + where C: Clone + std::marker::Send + Sync { + #[allow(unused_mut)] + fn delete_order(&self, order_id: &str) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::DELETE, "/store/order/{orderId}".to_string()) ; req = req.with_path_param("orderId".to_string(), order_id.to_string()); req = req.returns_nothing(); @@ -49,8 +53,9 @@ implStoreApi for StoreApiClient { req.execute(self.configuration.borrow()) } - fn get_inventory(&self, ) -> Box, Error = Error>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/store/inventory".to_string()) + #[allow(unused_mut)] + fn get_inventory(&self, ) -> Pin, Error>>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/store/inventory".to_string()) .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ in_header: true, in_query: false, @@ -61,16 +66,18 @@ implStoreApi for StoreApiClient { req.execute(self.configuration.borrow()) } - fn get_order_by_id(&self, order_id: i64) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/store/order/{orderId}".to_string()) + #[allow(unused_mut)] + fn get_order_by_id(&self, order_id: i64) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/store/order/{orderId}".to_string()) ; req = req.with_path_param("orderId".to_string(), order_id.to_string()); req.execute(self.configuration.borrow()) } - fn place_order(&self, order: crate::models::Order) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/store/order".to_string()) + #[allow(unused_mut)] + fn place_order(&self, body: crate::models::Order) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/store/order".to_string()) ; req = req.with_body_param(order); diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/user_api.rs index e7326d05c4d..2651e807362 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/user_api.rs @@ -4,27 +4,29 @@ * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. * * The version of the OpenAPI document: 1.0.0 - * + * * Generated by: https://openapi-generator.tech */ use std::rc::Rc; use std::borrow::Borrow; +use std::pin::Pin; #[allow(unused_imports)] use std::option::Option; use hyper; -use serde_json; use futures::Future; use super::{Error, configuration}; use super::request as __internal_request; -pub struct UserApiClient { +pub struct UserApiClient + where C: Clone + std::marker::Send + Sync + 'static { configuration: Rc>, } -impl UserApiClient { +impl UserApiClient + where C: Clone + std::marker::Send + Sync { pub fn new(configuration: Rc>) -> UserApiClient { UserApiClient { configuration, @@ -33,24 +35,21 @@ impl UserApiClient { } pub trait UserApi { - fn create_user(&self, user: crate::models::User) -> Box>>; - fn create_users_with_array_input(&self, user: Vec) -> Box>>; - fn create_users_with_list_input(&self, user: Vec) -> Box>>; - fn delete_user(&self, username: &str) -> Box>>; - fn get_user_by_name(&self, username: &str) -> Box>>; - fn login_user(&self, username: &str, password: &str) -> Box>>; - fn logout_user(&self, ) -> Box>>; - fn update_user(&self, username: &str, user: crate::models::User) -> Box>>; + fn create_user(&self, body: crate::models::User) -> Pin>>>; + fn create_users_with_array_input(&self, body: Vec) -> Pin>>>; + fn create_users_with_list_input(&self, body: Vec) -> Pin>>>; + fn delete_user(&self, username: &str) -> Pin>>>; + fn get_user_by_name(&self, username: &str) -> Pin>>>; + fn login_user(&self, username: &str, password: &str) -> Pin>>>; + fn logout_user(&self, ) -> Pin>>>; + fn update_user(&self, username: &str, body: crate::models::User) -> Pin>>>; } -implUserApi for UserApiClient { - fn create_user(&self, user: crate::models::User) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/user".to_string()) - .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ - in_header: true, - in_query: false, - param_name: "api_key".to_owned(), - })) +implUserApi for UserApiClient + where C: Clone + std::marker::Send + Sync { + #[allow(unused_mut)] + fn create_user(&self, body: crate::models::User) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/user".to_string()) ; req = req.with_body_param(user); req = req.returns_nothing(); @@ -58,13 +57,9 @@ implUserApi for UserApiClient { req.execute(self.configuration.borrow()) } - fn create_users_with_array_input(&self, user: Vec) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/user/createWithArray".to_string()) - .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ - in_header: true, - in_query: false, - param_name: "api_key".to_owned(), - })) + #[allow(unused_mut)] + fn create_users_with_array_input(&self, body: Vec) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/user/createWithArray".to_string()) ; req = req.with_body_param(user); req = req.returns_nothing(); @@ -72,13 +67,9 @@ implUserApi for UserApiClient { req.execute(self.configuration.borrow()) } - fn create_users_with_list_input(&self, user: Vec) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Post, "/user/createWithList".to_string()) - .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ - in_header: true, - in_query: false, - param_name: "api_key".to_owned(), - })) + #[allow(unused_mut)] + fn create_users_with_list_input(&self, body: Vec) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::POST, "/user/createWithList".to_string()) ; req = req.with_body_param(user); req = req.returns_nothing(); @@ -86,13 +77,9 @@ implUserApi for UserApiClient { req.execute(self.configuration.borrow()) } - fn delete_user(&self, username: &str) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Delete, "/user/{username}".to_string()) - .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ - in_header: true, - in_query: false, - param_name: "api_key".to_owned(), - })) + #[allow(unused_mut)] + fn delete_user(&self, username: &str) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::DELETE, "/user/{username}".to_string()) ; req = req.with_path_param("username".to_string(), username.to_string()); req = req.returns_nothing(); @@ -100,16 +87,18 @@ implUserApi for UserApiClient { req.execute(self.configuration.borrow()) } - fn get_user_by_name(&self, username: &str) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/user/{username}".to_string()) + #[allow(unused_mut)] + fn get_user_by_name(&self, username: &str) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/user/{username}".to_string()) ; req = req.with_path_param("username".to_string(), username.to_string()); req.execute(self.configuration.borrow()) } - fn login_user(&self, username: &str, password: &str) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/user/login".to_string()) + #[allow(unused_mut)] + fn login_user(&self, username: &str, password: &str) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/user/login".to_string()) ; req = req.with_query_param("username".to_string(), username.to_string()); req = req.with_query_param("password".to_string(), password.to_string()); @@ -117,26 +106,18 @@ implUserApi for UserApiClient { req.execute(self.configuration.borrow()) } - fn logout_user(&self, ) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Get, "/user/logout".to_string()) - .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ - in_header: true, - in_query: false, - param_name: "api_key".to_owned(), - })) + #[allow(unused_mut)] + fn logout_user(&self, ) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::GET, "/user/logout".to_string()) ; req = req.returns_nothing(); req.execute(self.configuration.borrow()) } - fn update_user(&self, username: &str, user: crate::models::User) -> Box>> { - let mut req = __internal_request::Request::new(hyper::Method::Put, "/user/{username}".to_string()) - .with_auth(__internal_request::Auth::ApiKey(__internal_request::ApiKey{ - in_header: true, - in_query: false, - param_name: "api_key".to_owned(), - })) + #[allow(unused_mut)] + fn update_user(&self, username: &str, body: crate::models::User) -> Pin>>> { + let mut req = __internal_request::Request::new(hyper::Method::PUT, "/user/{username}".to_string()) ; req = req.with_path_param("username".to_string(), username.to_string()); req = req.with_body_param(user);