mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-10 10:36:11 +00:00
[Rust] Add user agent handling for rust template (master) (#7375)
* Add user agent handling for rust template * Run ./bin/rust-petstore.sh
This commit is contained in:
committed by
William Cheng
parent
ea8b184931
commit
66be7a7910
@@ -1,12 +1,15 @@
|
||||
{{>partial_header}}
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
|
||||
use super::{Error, configuration};
|
||||
|
||||
pub struct {{{classname}}}Client<C: hyper::client::Connect> {
|
||||
@@ -57,6 +60,10 @@ impl<C: hyper::client::Connect>{{classname}} for {{classname}}Client<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{{#hasHeaderParams}}
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
|
||||
@@ -3,6 +3,7 @@ use hyper;
|
||||
|
||||
pub struct Configuration<C: hyper::client::Connect> {
|
||||
pub base_path: String,
|
||||
pub user_agent: Option<String>,
|
||||
pub client: hyper::client::Client<C>,
|
||||
}
|
||||
|
||||
@@ -10,6 +11,7 @@ impl<C: hyper::client::Connect> Configuration<C> {
|
||||
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
|
||||
Configuration {
|
||||
base_path: "{{{basePath}}}".to_owned(),
|
||||
user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}None{{/httpUserAgent}},
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
2.3.0-SNAPSHOT
|
||||
2.3.1-SNAPSHOT
|
||||
@@ -12,6 +12,7 @@ use hyper;
|
||||
|
||||
pub struct Configuration<C: hyper::client::Connect> {
|
||||
pub base_path: String,
|
||||
pub user_agent: Option<String>,
|
||||
pub client: hyper::client::Client<C>,
|
||||
}
|
||||
|
||||
@@ -19,6 +20,7 @@ impl<C: hyper::client::Connect> Configuration<C> {
|
||||
pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
|
||||
Configuration {
|
||||
base_path: "http://petstore.swagger.io/v2".to_owned(),
|
||||
user_agent: None,
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
|
||||
use super::{Error, configuration};
|
||||
|
||||
pub struct PetApiClient<C: hyper::client::Connect> {
|
||||
@@ -57,6 +60,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
@@ -85,6 +92,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
{
|
||||
let mut headers = req.headers_mut();
|
||||
headers.set_raw("api_key", api_key);
|
||||
@@ -116,6 +127,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -146,6 +161,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -173,6 +192,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -200,6 +223,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
@@ -228,6 +255,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -252,6 +283,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
|
||||
use super::{Error, configuration};
|
||||
|
||||
pub struct StoreApiClient<C: hyper::client::Connect> {
|
||||
@@ -53,6 +56,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -77,6 +84,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -104,6 +115,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -131,6 +146,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::borrow::Borrow;
|
||||
use std::borrow::Cow;
|
||||
|
||||
use hyper;
|
||||
use serde_json;
|
||||
use futures;
|
||||
use futures::{Future, Stream};
|
||||
|
||||
use hyper::header::UserAgent;
|
||||
|
||||
use super::{Error, configuration};
|
||||
|
||||
pub struct UserApiClient<C: hyper::client::Connect> {
|
||||
@@ -57,6 +60,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
@@ -85,6 +92,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
@@ -113,6 +124,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
@@ -141,6 +156,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -165,6 +184,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -196,6 +219,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -223,6 +250,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// send request
|
||||
@@ -247,6 +278,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
|
||||
// }
|
||||
let mut req = hyper::Request::new(method, uri.unwrap());
|
||||
|
||||
if let Some(ref user_agent) = configuration.user_agent {
|
||||
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
|
||||
}
|
||||
|
||||
|
||||
let serialized = serde_json::to_string(&body).unwrap();
|
||||
req.headers_mut().set(hyper::header::ContentType::json());
|
||||
|
||||
Reference in New Issue
Block a user