diff --git a/modules/swagger-codegen/src/main/resources/rust/api.mustache b/modules/swagger-codegen/src/main/resources/rust/api.mustache index 21c45ef38db..55604ca7933 100644 --- a/modules/swagger-codegen/src/main/resources/rust/api.mustache +++ b/modules/swagger-codegen/src/main/resources/rust/api.mustache @@ -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{{classname}} for {{classname}}Client { 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>> { let configuration: &configuration::Configuration = self.configuration.borrow(); +{{#hasAuthMethods}} + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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()) - {{#queryParams}} - .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}} + let query_string = { + let mut query = ::url::form_urlencoded::Serializer::new(String::new()); +{{#queryParams}} + query.append_pair("{{baseName}}", &{{paramName}}{{#isListContainer}}.join(","){{/isListContainer}}.to_string()); +{{/queryParams}} +{{#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{{classname}} for {{classname}}Client { } {{/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(); diff --git a/modules/swagger-codegen/src/main/resources/rust/configuration.mustache b/modules/swagger-codegen/src/main/resources/rust/configuration.mustache index c555c665860..ff2d673b27c 100644 --- a/modules/swagger-codegen/src/main/resources/rust/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/rust/configuration.mustache @@ -1,10 +1,22 @@ {{>partial_header}} use hyper; +use std::collections::HashMap; pub struct Configuration { pub base_path: String, pub user_agent: Option, pub client: hyper::client::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, } impl Configuration { @@ -13,6 +25,9 @@ impl Configuration { 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, } } } diff --git a/samples/client/petstore/rust/docs/UserApi.md b/samples/client/petstore/rust/docs/UserApi.md index 80ae627c3b4..6ccc9b08f36 100644 --- a/samples/client/petstore/rust/docs/UserApi.md +++ b/samples/client/petstore/rust/docs/UserApi.md @@ -132,7 +132,7 @@ Get user by user name Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **username** | **String**| The name that needs to be fetched. Use user1 for testing. | + **username** | **String**| The name that needs to be fetched. Use user1 for testing. | ### Return type diff --git a/samples/client/petstore/rust/src/apis/configuration.rs b/samples/client/petstore/rust/src/apis/configuration.rs index a5d8db713f0..e501db7b6a9 100644 --- a/samples/client/petstore/rust/src/apis/configuration.rs +++ b/samples/client/petstore/rust/src/apis/configuration.rs @@ -9,11 +9,23 @@ */ use hyper; +use std::collections::HashMap; pub struct Configuration { pub base_path: String, pub user_agent: Option, pub client: hyper::client::Client, + pub basic_auth: Option, + pub oauth_access_token: Option, + pub api_key: Option, + // TODO: take an oauth2 token source, similar to the go one +} + +pub type BasicAuth = (String, Option); + +pub struct ApiKey { + pub prefix: Option, + pub key: String, } impl Configuration { @@ -22,6 +34,9 @@ impl Configuration { 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, } } } diff --git a/samples/client/petstore/rust/src/apis/pet_api.rs b/samples/client/petstore/rust/src/apis/pet_api.rs index 315ffeec112..41199bc61ca 100644 --- a/samples/client/petstore/rust/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/src/apis/pet_api.rs @@ -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 @@ implPetApi for PetApiClient { fn add_pet(&self, body: ::models::Pet) -> Box>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { fn delete_pet(&self, pet_id: i64, api_key: &str) -> Box>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { 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 @@ implPetApi for PetApiClient { fn find_pets_by_status(&self, status: Vec) -> Box, Error = Error>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { fn find_pets_by_tags(&self, tags: Vec) -> Box, Error = Error>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { fn get_pet_by_id(&self, pet_id: i64) -> Box>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { fn update_pet(&self, body: ::models::Pet) -> Box>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { fn update_pet_with_form(&self, pet_id: i64, name: &str, status: &str) -> Box>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implPetApi for PetApiClient { fn upload_file(&self, pet_id: i64, additional_metadata: &str, file: ::models::File) -> Box>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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( diff --git a/samples/client/petstore/rust/src/apis/store_api.rs b/samples/client/petstore/rust/src/apis/store_api.rs index fe3c1d325c7..a4726b7b139 100644 --- a/samples/client/petstore/rust/src/apis/store_api.rs +++ b/samples/client/petstore/rust/src/apis/store_api.rs @@ -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 @@ implStoreApi for StoreApiClient { 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 @@ implStoreApi for StoreApiClient { + // send request Box::new( configuration.client.request(req) @@ -86,22 +93,44 @@ implStoreApi for StoreApiClient { fn get_inventory(&self, ) -> Box, Error = Error>> { let configuration: &configuration::Configuration = self.configuration.borrow(); + let mut auth_headers = HashMap::::new(); + let mut auth_query = HashMap::::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 @@ implStoreApi for StoreApiClient { 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 @@ implStoreApi for StoreApiClient { + // send request Box::new( configuration.client.request(req) @@ -176,20 +211,26 @@ implStoreApi for StoreApiClient { 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)); diff --git a/samples/client/petstore/rust/src/apis/user_api.rs b/samples/client/petstore/rust/src/apis/user_api.rs index c3c9f7d457e..947932c5a70 100644 --- a/samples/client/petstore/rust/src/apis/user_api.rs +++ b/samples/client/petstore/rust/src/apis/user_api.rs @@ -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 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { + // send request Box::new( configuration.client.request(req) @@ -227,14 +252,19 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { + // send request Box::new( configuration.client.request(req) @@ -271,18 +302,21 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { + // send request Box::new( configuration.client.request(req) @@ -319,14 +354,19 @@ implUserApi for UserApiClient { 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 @@ implUserApi for UserApiClient { + // send request Box::new( configuration.client.request(req) @@ -360,20 +401,26 @@ implUserApi for UserApiClient { 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));