[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:
Tristan Bourvon 2018-01-14 11:18:58 +01:00 committed by William Cheng
parent ea8b184931
commit 66be7a7910
7 changed files with 101 additions and 1 deletions

View File

@ -1,12 +1,15 @@
{{>partial_header}} {{>partial_header}}
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::borrow::Cow;
use hyper; use hyper;
use serde_json; use serde_json;
use futures; use futures;
use futures::{Future, Stream}; use futures::{Future, Stream};
use hyper::header::UserAgent;
use super::{Error, configuration}; use super::{Error, configuration};
pub struct {{{classname}}}Client<C: hyper::client::Connect> { 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()); 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}} {{#hasHeaderParams}}
{ {
let mut headers = req.headers_mut(); let mut headers = req.headers_mut();

View File

@ -3,6 +3,7 @@ use hyper;
pub struct Configuration<C: hyper::client::Connect> { pub struct Configuration<C: hyper::client::Connect> {
pub base_path: String, pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>, 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> { pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
Configuration { Configuration {
base_path: "{{{basePath}}}".to_owned(), base_path: "{{{basePath}}}".to_owned(),
user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}None{{/httpUserAgent}},
client: client, client: client,
} }
} }

View File

@ -1 +1 @@
2.3.0-SNAPSHOT 2.3.1-SNAPSHOT

View File

@ -12,6 +12,7 @@ use hyper;
pub struct Configuration<C: hyper::client::Connect> { pub struct Configuration<C: hyper::client::Connect> {
pub base_path: String, pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>, 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> { pub fn new(client: hyper::client::Client<C>) -> Configuration<C> {
Configuration { Configuration {
base_path: "http://petstore.swagger.io/v2".to_owned(), base_path: "http://petstore.swagger.io/v2".to_owned(),
user_agent: None,
client: client, client: client,
} }
} }

View File

@ -10,12 +10,15 @@
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::borrow::Cow;
use hyper; use hyper;
use serde_json; use serde_json;
use futures; use futures;
use futures::{Future, Stream}; use futures::{Future, Stream};
use hyper::header::UserAgent;
use super::{Error, configuration}; use super::{Error, configuration};
pub struct PetApiClient<C: hyper::client::Connect> { 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()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); 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()); 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(); let mut headers = req.headers_mut();
headers.set_raw("api_key", api_key); 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()); 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 // send request
@ -146,6 +161,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -173,6 +192,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -200,6 +223,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); 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()); 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 // send request
@ -252,6 +283,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request

View File

@ -10,12 +10,15 @@
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::borrow::Cow;
use hyper; use hyper;
use serde_json; use serde_json;
use futures; use futures;
use futures::{Future, Stream}; use futures::{Future, Stream};
use hyper::header::UserAgent;
use super::{Error, configuration}; use super::{Error, configuration};
pub struct StoreApiClient<C: hyper::client::Connect> { 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()); 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 // send request
@ -77,6 +84,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -104,6 +115,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -131,6 +146,10 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); req.headers_mut().set(hyper::header::ContentType::json());

View File

@ -10,12 +10,15 @@
use std::rc::Rc; use std::rc::Rc;
use std::borrow::Borrow; use std::borrow::Borrow;
use std::borrow::Cow;
use hyper; use hyper;
use serde_json; use serde_json;
use futures; use futures;
use futures::{Future, Stream}; use futures::{Future, Stream};
use hyper::header::UserAgent;
use super::{Error, configuration}; use super::{Error, configuration};
pub struct UserApiClient<C: hyper::client::Connect> { 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()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); 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()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); 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()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); 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()); 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 // send request
@ -165,6 +184,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -196,6 +219,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -223,6 +250,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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 // send request
@ -247,6 +278,10 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// } // }
let mut req = hyper::Request::new(method, uri.unwrap()); 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(); let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json()); req.headers_mut().set(hyper::header::ContentType::json());