From b0909ade6f3cc5e4b8931426184d80975641f51a Mon Sep 17 00:00:00 2001 From: Benjamin Gill Date: Mon, 30 Jul 2018 11:38:52 +0100 Subject: [PATCH] [rust-server] add support for '|' in path segments (#667) * Added encoding for vertical bar character in object IDs for client requests * Updated sample --- .../resources/rust-server/client-mod.mustache | 10 ++++++- .../main/resources/rust-server/lib.mustache | 3 +++ .../src/client/mod.rs | 26 ++++++++++++------- .../src/lib.rs | 3 +++ 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache b/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache index 21b1b469f85..ec0c88692d1 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/client-mod.mustache @@ -43,6 +43,14 @@ use {Api{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}, }; use models; +define_encode_set! { + /// This encode set is used for object IDs + /// + /// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`, + /// the vertical bar (|) is encoded. + pub ID_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'|'} +} + /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. fn into_base_path(input: &str, correct_scheme: Option<&'static str>) -> Result { // First convert to Uri, since a base path is a subset of Uri. @@ -246,7 +254,7 @@ impl Api for Client where let uri = format!( "{}{{{basePathWithoutHost}}}{{path}}{{#queryParams}}{{#-first}}?{{/-first}}{{=<% %>=}}{<% paramName %>}<%={{ }}=%>{{/queryParams}}", - self.base_path{{#pathParams}}, {{{baseName}}}=utf8_percent_encode(¶m_{{{paramName}}}.to_string(), PATH_SEGMENT_ENCODE_SET){{/pathParams}}{{#queryParams}}, + self.base_path{{#pathParams}}, {{{baseName}}}=utf8_percent_encode(¶m_{{{paramName}}}.to_string(), ID_ENCODE_SET){{/pathParams}}{{#queryParams}}, {{{paramName}}}=utf8_percent_encode(&query_{{{paramName}}}, QUERY_ENCODE_SET){{/queryParams}} ); diff --git a/modules/openapi-generator/src/main/resources/rust-server/lib.mustache b/modules/openapi-generator/src/main/resources/rust-server/lib.mustache index 371962bf6d8..bca0608ecf9 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/lib.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/lib.mustache @@ -19,6 +19,9 @@ extern crate hyper; extern crate swagger; +#[macro_use] +extern crate url; + use futures::Stream; use std::io::Error; diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs index 42c2aac4b0c..c0c34329339 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/client/mod.rs @@ -74,6 +74,14 @@ use {Api, }; use models; +define_encode_set! { + /// This encode set is used for object IDs + /// + /// Aside from the special characters defined in the `PATH_SEGMENT_ENCODE_SET`, + /// the vertical bar (|) is encoded. + pub ID_ENCODE_SET = [PATH_SEGMENT_ENCODE_SET] | {'|'} +} + /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. fn into_base_path(input: &str, correct_scheme: Option<&'static str>) -> Result { // First convert to Uri, since a base path is a subset of Uri. @@ -1236,7 +1244,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/pet/{petId}", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -1461,7 +1469,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/pet/{petId}", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -1629,7 +1637,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/pet/{petId}", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -1693,7 +1701,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/pet/{petId}/uploadImage", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -1767,7 +1775,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/store/order/{order_id}", - self.base_path, order_id=utf8_percent_encode(¶m_order_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, order_id=utf8_percent_encode(¶m_order_id.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -1900,7 +1908,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/store/order/{order_id}", - self.base_path, order_id=utf8_percent_encode(¶m_order_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, order_id=utf8_percent_encode(¶m_order_id.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -2262,7 +2270,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/user/{username}", - self.base_path, username=utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, username=utf8_percent_encode(¶m_username.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -2328,7 +2336,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/user/{username}", - self.base_path, username=utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, username=utf8_percent_encode(¶m_username.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { @@ -2566,7 +2574,7 @@ if let Some(body) = body { let uri = format!( "{}/v2/user/{username}", - self.base_path, username=utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, username=utf8_percent_encode(¶m_username.to_string(), ID_ENCODE_SET) ); let uri = match Uri::from_str(&uri) { diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs index 2e3dc8744bb..a3034479d5d 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/lib.rs @@ -19,6 +19,9 @@ extern crate hyper; extern crate swagger; +#[macro_use] +extern crate url; + use futures::Stream; use std::io::Error;