From d98a0e4aff598c6bfd898f38f46b482c05dd1cf4 Mon Sep 17 00:00:00 2001 From: boxdot Date: Fri, 15 Feb 2019 08:34:28 +0100 Subject: [PATCH 1/2] Use oauth token for basic bearer auth in Rust. --- .../src/main/resources/rust/reqwest/api.mustache | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index e63b2b08ff9c..b782558fce54 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -78,15 +78,22 @@ impl {{{classname}}} for {{{classname}}}Client { {{/isKeyInHeader}} {{/isApiKey}} {{#isBasic}} + {{^isBasicBearer}} if let Some(ref auth_conf) = configuration.basic_auth { req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned()); }; + {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} if let Some(ref token) = configuration.oauth_access_token { req_builder = req_builder.bearer_auth(token.to_owned()); }; {{/isOAuth}} + {{#isBasicBearer}} + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + {{/isBasicBearer}} {{/authMethods}} {{/hasAuthMethods}} {{#isMultipart}} From 97bdc4d729f1d84ad4ff66105dc63395ea304871 Mon Sep 17 00:00:00 2001 From: Gabriel Feron Date: Tue, 19 Feb 2019 20:40:23 +0100 Subject: [PATCH 2/2] Add bearer_access_token instead of reusing oauth_access_token --- .../src/main/resources/rust/reqwest/api.mustache | 10 +++++----- .../main/resources/rust/reqwest/configuration.mustache | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index b782558fce54..e6706f7afe10 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -83,17 +83,17 @@ impl {{{classname}}} for {{{classname}}}Client { req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned()); }; {{/isBasicBearer}} + {{#isBasicBearer}} + if let Some(ref token) = configuration.bearer_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); + }; + {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} if let Some(ref token) = configuration.oauth_access_token { req_builder = req_builder.bearer_auth(token.to_owned()); }; {{/isOAuth}} - {{#isBasicBearer}} - if let Some(ref token) = configuration.oauth_access_token { - req_builder = req_builder.bearer_auth(token.to_owned()); - }; - {{/isBasicBearer}} {{/authMethods}} {{/hasAuthMethods}} {{#isMultipart}} diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/configuration.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/configuration.mustache index 5b9c437863aa..c12590dfc2ac 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/configuration.mustache @@ -8,6 +8,7 @@ pub struct Configuration { pub client: reqwest::Client, pub basic_auth: Option, pub oauth_access_token: Option, + pub bearer_access_token: Option, pub api_key: Option, // TODO: take an oauth2 token source, similar to the go one } @@ -33,6 +34,7 @@ impl Default for Configuration { client: reqwest::Client::new(), basic_auth: None, oauth_access_token: None, + bearer_access_token: None, api_key: None, } }