[Rust] Implement minimal auth support (#7338)

* [Rust] Implement minimal auth support

This is pretty much the bare minimum needed to get v2 auth working.

This is partly based on the Go implementation.

* [Rust] properly format query string

* [Rust] Improve auth formatting

* [Rust] Regenerate petstore sample
This commit is contained in:
Euan Kemp 2018-04-01 23:58:26 -07:00 committed by William Cheng
parent 6c7813e79c
commit b443573945
7 changed files with 427 additions and 84 deletions

View File

@ -2,6 +2,7 @@
use std::rc::Rc;
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::HashMap;
use hyper;
use serde_json;
@ -39,26 +40,71 @@ impl<C: hyper::client::Connect>{{classname}} for {{classname}}Client<C> {
fn {{{operationId}}}(&self, {{#allParams}}{{paramName}}: {{#isString}}&str{{/isString}}{{#isUuid}}&str{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}::models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) -> Box<Future<Item = {{^returnType}}(){{/returnType}}{{#returnType}}{{{.}}}{{/returnType}}, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
{{#hasAuthMethods}}
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
{{#authMethods}}
{{#isApiKey}}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let val = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
{{#isKeyInHeader}}
auth_headers.insert("{{keyParamName}}".to_owned(), val);
{{/isKeyInHeader}}
{{#isKeyInQuery}}
auth_query.insert("{{keyParamName}}".to_owned(), val);
{{/isKeyInQuery}}
};
{{/isApiKey}}
{{#isBasic}}
if let Some(ref auth_conf) = configuration.basic_auth {
let auth = hyper::header::Authorization(
hyper::header::Basic {
username: auth_conf.0.to_owned(),
password: auth_conf.1.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
{{/isBasic}}
{{#isOAuth}}
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
{{/isOAuth}}
{{/authMethods}}
{{/hasAuthMethods}}
let method = hyper::Method::{{httpMethod}};
{{^hasQueryParams}}
let uri_str = format!("{}{{{path}}}", configuration.base_path{{#pathParams}}, {{baseName}}={{paramName}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{/pathParams}});
{{/hasQueryParams}}
{{#hasQueryParams}}
let query = ::url::form_urlencoded::Serializer::new(String::new())
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
{{#queryParams}}
.append_pair("{{baseName}}", &{{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string())
query.append_pair("{{baseName}}", &{{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string());
{{/queryParams}}
.finish();
let uri_str = format!("{}{{{path}}}{}", configuration.base_path, query{{#pathParams}}, {{baseName}}={{paramName}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{/pathParams}});
{{/hasQueryParams}}
{{#hasAuthMethods}}
for (key, val) in &auth_query {
query.append_pair(key, val);
}
{{/hasAuthMethods}}
query.finish()
};
let uri_str = format!("{}{{{path}}}?{}", configuration.base_path, query_string{{#pathParams}}, {{baseName}}={{paramName}}{{#isListContainer}}.join(",").as_ref(){{/isListContainer}}{{/pathParams}});
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -73,6 +119,12 @@ impl<C: hyper::client::Connect>{{classname}} for {{classname}}Client<C> {
}
{{/hasHeaderParams}}
{{#hasAuthMethods}}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
{{/hasAuthMethods}}
{{#hasBodyParam}}
{{#bodyParams}}
let serialized = serde_json::to_string(&{{paramName}}).unwrap();

View File

@ -1,10 +1,22 @@
{{>partial_header}}
use hyper;
use std::collections::HashMap;
pub struct Configuration<C: hyper::client::Connect> {
pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub api_key: Option<ApiKey>,
// TODO: take an oauth2 token source, similar to the go one
}
pub type BasicAuth = (String, Option<String>);
pub struct ApiKey {
pub prefix: Option<String>,
pub key: String,
}
impl<C: hyper::client::Connect> Configuration<C> {
@ -13,6 +25,9 @@ impl<C: hyper::client::Connect> Configuration<C> {
base_path: "{{{basePath}}}".to_owned(),
user_agent: {{#httpUserAgent}}Some("{{{.}}}".to_owned()){{/httpUserAgent}}{{^httpUserAgent}}Some("Swagger-Codegen/{{version}}/rust".to_owned()){{/httpUserAgent}},
client: client,
basic_auth: None,
oauth_access_token: None,
api_key: None,
}
}
}

View File

@ -9,11 +9,23 @@
*/
use hyper;
use std::collections::HashMap;
pub struct Configuration<C: hyper::client::Connect> {
pub base_path: String,
pub user_agent: Option<String>,
pub client: hyper::client::Client<C>,
pub basic_auth: Option<BasicAuth>,
pub oauth_access_token: Option<String>,
pub api_key: Option<ApiKey>,
// TODO: take an oauth2 token source, similar to the go one
}
pub type BasicAuth = (String, Option<String>);
pub struct ApiKey {
pub prefix: Option<String>,
pub key: String,
}
impl<C: hyper::client::Connect> Configuration<C> {
@ -22,6 +34,9 @@ impl<C: hyper::client::Connect> Configuration<C> {
base_path: "http://petstore.swagger.io/v2".to_owned(),
user_agent: Some("Swagger-Codegen/1.0.0/rust".to_owned()),
client: client,
basic_auth: None,
oauth_access_token: None,
api_key: None,
}
}
}

View File

@ -11,6 +11,7 @@
use std::rc::Rc;
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::HashMap;
use hyper;
use serde_json;
@ -49,22 +50,44 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn add_pet(&self, body: ::models::Pet) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Post;
let uri_str = format!("{}/pet", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
@ -94,16 +117,34 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn delete_pet(&self, pet_id: i64, api_key: &str) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Delete;
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet/{petId}?{}", configuration.base_path, query_string, petId=pet_id);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -114,6 +155,10 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
headers.set_raw("api_key", api_key);
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(
@ -139,25 +184,45 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn find_pets_by_status(&self, status: Vec<String>) -> Box<Future<Item = Vec<::models::Pet>, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Get;
let query = ::url::form_urlencoded::Serializer::new(String::new())
.append_pair("status", &status.join(",").to_string())
.finish();
let uri_str = format!("{}/pet/findByStatus{}", configuration.base_path, query);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("status", &status.join(",").to_string());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet/findByStatus?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(
@ -186,25 +251,45 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn find_pets_by_tags(&self, tags: Vec<String>) -> Box<Future<Item = Vec<::models::Pet>, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Get;
let query = ::url::form_urlencoded::Serializer::new(String::new())
.append_pair("tags", &tags.join(",").to_string())
.finish();
let uri_str = format!("{}/pet/findByTags{}", configuration.base_path, query);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("tags", &tags.join(",").to_string());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet/findByTags?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(
@ -233,22 +318,44 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn get_pet_by_id(&self, pet_id: i64) -> Box<Future<Item = ::models::Pet, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let val = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
auth_headers.insert("api_key".to_owned(), val);
};
let method = hyper::Method::Get;
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet/{petId}?{}", configuration.base_path, query_string, petId=pet_id);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(
@ -277,22 +384,44 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn update_pet(&self, body: ::models::Pet) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Put;
let uri_str = format!("{}/pet", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
let serialized = serde_json::to_string(&body).unwrap();
req.headers_mut().set(hyper::header::ContentType::json());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
@ -322,22 +451,44 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn update_pet_with_form(&self, pet_id: i64, name: &str, status: &str) -> Box<Future<Item = (), Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Post;
let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet/{petId}?{}", configuration.base_path, query_string, petId=pet_id);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(
@ -363,22 +514,44 @@ impl<C: hyper::client::Connect>PetApi for PetApiClient<C> {
fn upload_file(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box<Future<Item = ::models::ApiResponse, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref token) = configuration.oauth_access_token {
let auth = hyper::header::Authorization(
hyper::header::Bearer {
token: token.to_owned(),
}
);
auth_headers.insert("Authorization".to_owned(), auth.to_string());
};
let method = hyper::Method::Post;
let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=pet_id);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/pet/{petId}/uploadImage?{}", configuration.base_path, query_string, petId=pet_id);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(

View File

@ -11,6 +11,7 @@
use std::rc::Rc;
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::HashMap;
use hyper;
use serde_json;
@ -47,14 +48,19 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
let method = hyper::Method::Delete;
let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=order_id);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/store/order/{orderId}?{}", configuration.base_path, query_string, orderId=order_id);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -62,6 +68,7 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
// send request
Box::new(
configuration.client.request(req)
@ -86,22 +93,44 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
fn get_inventory(&self, ) -> Box<Future<Item = ::std::collections::HashMap<String, i32>, Error = Error<serde_json::Value>>> {
let configuration: &configuration::Configuration<C> = self.configuration.borrow();
let mut auth_headers = HashMap::<String, String>::new();
let mut auth_query = HashMap::<String, String>::new();
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let val = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
auth_headers.insert("api_key".to_owned(), val);
};
let method = hyper::Method::Get;
let uri_str = format!("{}/store/inventory", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
for (key, val) in &auth_query {
query.append_pair(key, val);
}
query.finish()
};
let uri_str = format!("{}/store/inventory?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
}
for (key, val) in auth_headers {
req.headers_mut().set_raw(key, val);
}
// send request
Box::new(
@ -132,14 +161,19 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
let method = hyper::Method::Get;
let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=order_id);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/store/order/{orderId}?{}", configuration.base_path, query_string, orderId=order_id);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -147,6 +181,7 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
// send request
Box::new(
configuration.client.request(req)
@ -176,20 +211,26 @@ impl<C: hyper::client::Connect>StoreApi for StoreApiClient<C> {
let method = hyper::Method::Post;
let uri_str = format!("{}/store/order", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/store/order?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
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());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));

View File

@ -11,6 +11,7 @@
use std::rc::Rc;
use std::borrow::Borrow;
use std::borrow::Cow;
use std::collections::HashMap;
use hyper;
use serde_json;
@ -51,20 +52,26 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Post;
let uri_str = format!("{}/user", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
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());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
@ -96,20 +103,26 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Post;
let uri_str = format!("{}/user/createWithArray", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user/createWithArray?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
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());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
@ -141,20 +154,26 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Post;
let uri_str = format!("{}/user/createWithList", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user/createWithList?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
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());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));
@ -186,14 +205,19 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Delete;
let uri_str = format!("{}/user/{username}", configuration.base_path, username=username);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user/{username}?{}", configuration.base_path, query_string, username=username);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -201,6 +225,7 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// send request
Box::new(
configuration.client.request(req)
@ -227,14 +252,19 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Get;
let uri_str = format!("{}/user/{username}", configuration.base_path, username=username);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user/{username}?{}", configuration.base_path, query_string, username=username);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -242,6 +272,7 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// send request
Box::new(
configuration.client.request(req)
@ -271,18 +302,21 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Get;
let query = ::url::form_urlencoded::Serializer::new(String::new())
.append_pair("username", &username.to_string())
.append_pair("password", &password.to_string())
.finish();
let uri_str = format!("{}/user/login{}", configuration.base_path, query);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.append_pair("username", &username.to_string());
query.append_pair("password", &password.to_string());
query.finish()
};
let uri_str = format!("{}/user/login?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -290,6 +324,7 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// send request
Box::new(
configuration.client.request(req)
@ -319,14 +354,19 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Get;
let uri_str = format!("{}/user/logout", configuration.base_path);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user/logout?{}", configuration.base_path, query_string);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
if let Some(ref user_agent) = configuration.user_agent {
req.headers_mut().set(UserAgent::new(Cow::Owned(user_agent.clone())));
@ -334,6 +374,7 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
// send request
Box::new(
configuration.client.request(req)
@ -360,20 +401,26 @@ impl<C: hyper::client::Connect>UserApi for UserApiClient<C> {
let method = hyper::Method::Put;
let uri_str = format!("{}/user/{username}", configuration.base_path, username=username);
let query_string = {
let mut query = ::url::form_urlencoded::Serializer::new(String::new());
query.finish()
};
let uri_str = format!("{}/user/{username}?{}", configuration.base_path, query_string, username=username);
let uri = uri_str.parse();
// TODO(farcaller): handle error
// if let Err(e) = uri {
// return Box::new(futures::future::err(e));
// }
let mut req = hyper::Request::new(method, uri.unwrap());
let mut uri: hyper::Uri = uri_str.parse().unwrap();
let mut req = hyper::Request::new(method, uri);
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());
req.headers_mut().set(hyper::header::ContentLength(serialized.len() as u64));