(
self,
conf: &configuration::Configuration<C>,
)
| 108 | } |
| 109 | |
| 110 | pub fn execute<'a, C, U>( |
| 111 | self, |
| 112 | conf: &configuration::Configuration<C>, |
| 113 | ) -> Pin<Box<dyn Future<Output = Result<U, Error>> + 'a + Send>> |
| 114 | where |
| 115 | C: Connect + Clone + std::marker::Send + Sync, |
| 116 | U: Sized + std::marker::Send + 'a, |
| 117 | for<'de> U: serde::Deserialize<'de>, |
| 118 | { |
| 119 | let mut query_string = ::url::form_urlencoded::Serializer::new("".to_owned()); |
| 120 | |
| 121 | let mut path = self.path; |
| 122 | for (k, v) in self.path_params { |
| 123 | // replace {id} with the value of the id path param |
| 124 | path = path.replace(&format!("{{{}}}", k), &v); |
| 125 | } |
| 126 | |
| 127 | for (key, val) in self.query_params { |
| 128 | query_string.append_pair(&key, &val); |
| 129 | } |
| 130 | |
| 131 | let query_string_str = query_string.finish(); |
| 132 | if !query_string_str.is_empty() { |
| 133 | path += "?"; |
| 134 | path += &query_string_str; |
| 135 | } |
| 136 | let uri: hyper::Uri = Uri::new(&conf.base_path, &format!("/api/v1{path}")).into(); |
| 137 | let mut req_builder = hyper::Request::builder().uri(uri).method(self.method); |
| 138 | |
| 139 | // Detect the authorization type if it hasn't been set. |
| 140 | let auth = self.auth.unwrap_or_else(|| |
| 141 | if conf.api_key.is_some() { |
| 142 | panic!("Cannot automatically set the API key from the configuration, it must be specified in the OpenAPI definition") |
| 143 | } else if conf.oauth_access_token.is_some() { |
| 144 | Auth::Oauth |
| 145 | } else if conf.basic_auth.is_some() { |
| 146 | Auth::Basic |
| 147 | } else { |
| 148 | Auth::None |
| 149 | } |
| 150 | ); |
| 151 | match auth { |
| 152 | Auth::ApiKey(apikey) => { |
| 153 | if let Some(ref key) = conf.api_key { |
| 154 | let val = apikey.key(&key.prefix, &key.key); |
| 155 | if apikey.in_query { |
| 156 | query_string.append_pair(&apikey.param_name, &val); |
| 157 | } |
| 158 | if apikey.in_header { |
| 159 | req_builder = req_builder.header(&apikey.param_name, val); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | Auth::Basic => { |
| 164 | if let Some(ref auth_conf) = conf.basic_auth { |
| 165 | let mut text = auth_conf.0.clone(); |
| 166 | text.push(':'); |
| 167 | if let Some(ref pass) = auth_conf.1 { |
no test coverage detected