From 67d23fcf7e60647b2275c9b18582a76cc91cee9c Mon Sep 17 00:00:00 2001 From: aandyl Date: Thu, 16 Jan 2020 23:44:23 -0800 Subject: [PATCH] [Rust Server] fix handling of special characters in path param names (#4897) * test for hyphen in path parameter name * fix handling of hyphens in path parameter names --- .../codegen/languages/RustServerCodegen.java | 22 +++- .../resources/rust-server/client-mod.mustache | 4 +- .../resources/rust-server/server-mod.mustache | 4 +- ...ith-fake-endpoints-models-for-testing.yaml | 19 +++ .../README.md | 2 + .../api/openapi.yaml | 17 +++ .../docs/fake_api.md | 28 ++++ .../examples/client.rs | 7 + .../examples/server_lib/server.rs | 8 ++ .../src/client/mod.rs | 78 +++++++++-- .../src/lib.rs | 17 +++ .../src/server/mod.rs | 124 +++++++++++++----- 12 files changed, 283 insertions(+), 47 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java index c9535fe9260..16e2da7a78c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustServerCodegen.java @@ -552,6 +552,16 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { Map definitions = ModelUtils.getSchemas(this.openAPI); CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers); + String pathFormatString = op.path; + for (CodegenParameter param : op.pathParams) { + // Replace {baseName} with {paramName} for format string + String paramSearch = "{" + param.baseName + "}"; + String paramReplace = "{" + param.paramName + "}"; + + pathFormatString = pathFormatString.replace(paramSearch, paramReplace); + } + op.vendorExtensions.put("pathFormatString", pathFormatString); + // The Rust code will need to contain a series of regular expressions. // For performance, we'll construct these at start-of-day and re-use // them. That means we need labels for them. @@ -584,10 +594,18 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig { } // Don't prefix with '^' so that the templates can put the // basePath on the front. - pathSetEntry.put("pathRegEx", op.path.replace("{", "(?P<").replace("}", ">[^/?#]*)") + "$"); + String pathRegEx = op.path; + for (CodegenParameter param : op.pathParams) { + // Replace {baseName} with (?P[^/?#]*) for regex + String paramSearch = "{" + param.baseName + "}"; + String paramReplace = "(?P<" + param.paramName + ">[^/?#]*)"; + + pathRegEx = pathRegEx.replace(paramSearch, paramReplace); + } + + pathSetEntry.put("pathRegEx", pathRegEx + "$"); pathSetMap.put(pathId, pathSetEntry); } - op.vendorExtensions.put("operation_id", underscore(op.operationId)); op.vendorExtensions.put("uppercase_operation_id", underscore(op.operationId).toUpperCase(Locale.ROOT)); op.vendorExtensions.put("path", op.path.replace("{", ":").replace("}", "")); 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 f6176fc5bd4..4bc03901ad4 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 @@ -262,8 +262,8 @@ impl Api for Client where {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}} fn {{#vendorExtensions}}{{{operation_id}}}{{/vendorExtensions}}(&self{{#allParams}}, param_{{{paramName}}}: {{^required}}Option<{{/required}}{{#isListContainer}}&{{/isListContainer}}{{{dataType}}}{{^required}}>{{/required}}{{/allParams}}, context: &C) -> Box> { let mut uri = format!( - "{}{{{basePathWithoutHost}}}{{path}}", - self.base_path{{#pathParams}}, {{{baseName}}}=utf8_percent_encode(¶m_{{{paramName}}}.to_string(), ID_ENCODE_SET){{/pathParams}} + "{}{{{basePathWithoutHost}}}{{#vendorExtensions}}{{pathFormatString}}{{/vendorExtensions}}", + self.base_path{{#pathParams}}, {{{paramName}}}=utf8_percent_encode(¶m_{{{paramName}}}.to_string(), ID_ENCODE_SET){{/pathParams}} ); let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned()); diff --git a/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache b/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache index 591609bbbe0..16d9ef55dd0 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/server-mod.mustache @@ -195,12 +195,12 @@ where {{/hasPathParams}} {{/vendorExtensions}} {{#pathParams}} - let param_{{{paramName}}} = match percent_encoding::percent_decode(path_params["{{{baseName}}}"].as_bytes()).decode_utf8() { + let param_{{{paramName}}} = match percent_encoding::percent_decode(path_params["{{{paramName}}}"].as_bytes()).decode_utf8() { Ok(param_{{{paramName}}}) => match param_{{{paramName}}}.parse::<{{{dataType}}}>() { Ok(param_{{{paramName}}}) => param_{{{paramName}}}, Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter {{{baseName}}}: {:?}", e)))), }, - Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["{{{baseName}}}"])))) + Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["{{{paramName}}}"])))) }; {{/pathParams}} {{#headerParams}} diff --git a/modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml index 3850646ac24..961a249143d 100644 --- a/modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml @@ -946,6 +946,25 @@ paths: description: successful operation schema: $ref: '#/definitions/Client' + /fake/hyphenParam/{hyphen-param}: + get: + tags: + - fake + description: To test hyphen in path parameter name + operationId: hyphenParam + consumes: + - application/json + produces: + - application/json + parameters: + - name: hyphen-param + in: path + description: Parameter with hyphen in name + required: true + type: string + responses: + 200: + description: Success securityDefinitions: petstore_auth: type: oauth2 diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md index fa4062102f5..c800a04fab3 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/README.md @@ -66,6 +66,7 @@ cargo run --example client FakeOuterBooleanSerialize cargo run --example client FakeOuterCompositeSerialize cargo run --example client FakeOuterNumberSerialize cargo run --example client FakeOuterStringSerialize +cargo run --example client HyphenParam cargo run --example client TestBodyWithQueryParams cargo run --example client TestClientModel cargo run --example client TestEndpointParameters @@ -131,6 +132,7 @@ Method | HTTP request | Description [**fakeOuterCompositeSerialize**](docs/fake_api.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | [**fakeOuterNumberSerialize**](docs/fake_api.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | [**fakeOuterStringSerialize**](docs/fake_api.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | +[**hyphenParam**](docs/fake_api.md#hyphenParam) | **GET** /fake/hyphenParam/{hyphen-param} | [**testBodyWithQueryParams**](docs/fake_api.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params | [**testClientModel**](docs/fake_api.md#testClientModel) | **PATCH** /fake | To test \"client\" model [**testEndpointParameters**](docs/fake_api.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml index b7cf57122c9..8e1b2de1432 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/api/openapi.yaml @@ -984,6 +984,23 @@ paths: tags: - $another-fake? x-codegen-request-body-name: body + /fake/hyphenParam/{hyphen-param}: + get: + description: To test hyphen in path parameter name + operationId: hyphenParam + parameters: + - description: Parameter with hyphen in name + in: path + name: hyphen-param + required: true + schema: + type: string + responses: + 200: + content: {} + description: Success + tags: + - fake components: schemas: Order: diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md index a3f4d9e9366..20789c0ad88 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/docs/fake_api.md @@ -8,6 +8,7 @@ Method | HTTP request | Description **fakeOuterCompositeSerialize**](fake_api.md#fakeOuterCompositeSerialize) | **POST** /fake/outer/composite | **fakeOuterNumberSerialize**](fake_api.md#fakeOuterNumberSerialize) | **POST** /fake/outer/number | **fakeOuterStringSerialize**](fake_api.md#fakeOuterStringSerialize) | **POST** /fake/outer/string | +**hyphenParam**](fake_api.md#hyphenParam) | **GET** /fake/hyphenParam/{hyphen-param} | **testBodyWithQueryParams**](fake_api.md#testBodyWithQueryParams) | **PUT** /fake/body-with-query-params | **testClientModel**](fake_api.md#testClientModel) | **PATCH** /fake | To test \"client\" model **testEndpointParameters**](fake_api.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 @@ -152,6 +153,33 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **hyphenParam** +> hyphenParam(hyphen_param) + + +To test hyphen in path parameter name + +### Required Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **hyphen_param** | **String**| Parameter with hyphen in name | + +### Return type + + (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: Not defined + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **testBodyWithQueryParams** > testBodyWithQueryParams(query, body) diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs index a55c070e0c3..7e87c4bb742 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/client.rs @@ -24,6 +24,7 @@ use petstore_with_fake_endpoints_models_for_testing::{ApiNoContext, ContextWrapp FakeOuterCompositeSerializeResponse, FakeOuterNumberSerializeResponse, FakeOuterStringSerializeResponse, + HyphenParamResponse, TestBodyWithQueryParamsResponse, TestClientModelResponse, TestEndpointParametersResponse, @@ -63,6 +64,7 @@ fn main() { "FakeOuterCompositeSerialize", "FakeOuterNumberSerialize", "FakeOuterStringSerialize", + "HyphenParam", "TestEndpointParameters", "TestEnumParameters", "TestJsonFormData", @@ -147,6 +149,11 @@ fn main() { println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, + Some("HyphenParam") => { + let result = core.run(client.hyphen_param("hyphen_param_example".to_string())); + println!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); + }, + // Disabled because there's no example. // Some("TestBodyWithQueryParams") => { // let result = core.run(client.test_body_with_query_params("query_example".to_string(), ???)); diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs index 1aca2d246f5..48745fe5ef5 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/examples/server_lib/server.rs @@ -16,6 +16,7 @@ use petstore_with_fake_endpoints_models_for_testing::{Api, ApiError, FakeOuterCompositeSerializeResponse, FakeOuterNumberSerializeResponse, FakeOuterStringSerializeResponse, + HyphenParamResponse, TestBodyWithQueryParamsResponse, TestClientModelResponse, TestEndpointParametersResponse, @@ -95,6 +96,13 @@ impl Api for Server where C: Has{ } + fn hyphen_param(&self, hyphen_param: String, context: &C) -> Box> { + let context = context.clone(); + println!("hyphen_param(\"{}\") - X-Span-ID: {:?}", hyphen_param, context.get().0.clone()); + Box::new(futures::failed("Generic failure".into())) + } + + fn test_body_with_query_params(&self, query: String, body: models::User, context: &C) -> Box> { let context = context.clone(); println!("test_body_with_query_params(\"{}\", {:?}) - X-Span-ID: {:?}", query, body, context.get().0.clone()); 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 9976c76758b..9c03e6ef31b 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 @@ -49,6 +49,7 @@ use {Api, FakeOuterCompositeSerializeResponse, FakeOuterNumberSerializeResponse, FakeOuterStringSerializeResponse, + HyphenParamResponse, TestBodyWithQueryParamsResponse, TestClientModelResponse, TestEndpointParametersResponse, @@ -678,6 +679,67 @@ impl Api for Client where } + fn hyphen_param(&self, param_hyphen_param: String, context: &C) -> Box> { + let mut uri = format!( + "{}/v2/fake/hyphenParam/{hyphen_param}", + self.base_path, hyphen_param=utf8_percent_encode(¶m_hyphen_param.to_string(), ID_ENCODE_SET) + ); + + let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned()); + + + let query_string_str = query_string.finish(); + if !query_string_str.is_empty() { + uri += "?"; + uri += &query_string_str; + } + + let uri = match Uri::from_str(&uri) { + Ok(uri) => uri, + Err(err) => return Box::new(futures::done(Err(ApiError(format!("Unable to build URI: {}", err))))), + }; + + let mut request = hyper::Request::new(hyper::Method::Get, uri); + + + request.headers_mut().set(XSpanId((context as &dyn Has).get().0.clone())); + Box::new(self.client_service.call(request) + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(|mut response| { + match response.status().as_u16() { + 200 => { + let body = response.body(); + Box::new( + + future::ok( + HyphenParamResponse::Success + ) + ) as Box> + }, + code => { + let headers = response.headers().clone(); + Box::new(response.body() + .take(100) + .concat2() + .then(move |body| + future::err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", + code, + headers, + match body { + Ok(ref body) => match str::from_utf8(body) { + Ok(body) => Cow::from(body), + Err(e) => Cow::from(format!("", e)), + }, + Err(e) => Cow::from(format!("", e)), + }))) + ) + ) as Box> + } + } + })) + + } + fn test_body_with_query_params(&self, param_query: String, param_body: models::User, context: &C) -> Box> { let mut uri = format!( "{}/v2/fake/body-with-query-params", @@ -1310,8 +1372,8 @@ impl Api for Client where fn delete_pet(&self, param_pet_id: i64, param_api_key: Option, context: &C) -> Box> { let mut uri = format!( - "{}/v2/pet/{petId}", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) + "{}/v2/pet/{pet_id}", + self.base_path, pet_id=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned()); @@ -1577,8 +1639,8 @@ impl Api for Client where fn get_pet_by_id(&self, param_pet_id: i64, context: &C) -> Box> { let mut uri = format!( - "{}/v2/pet/{petId}", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) + "{}/v2/pet/{pet_id}", + self.base_path, pet_id=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned()); @@ -1776,8 +1838,8 @@ impl Api for Client where fn update_pet_with_form(&self, param_pet_id: i64, param_name: Option, param_status: Option, context: &C) -> Box> { let mut uri = format!( - "{}/v2/pet/{petId}", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) + "{}/v2/pet/{pet_id}", + self.base_path, pet_id=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned()); @@ -1857,8 +1919,8 @@ impl Api for Client where fn upload_file(&self, param_pet_id: i64, param_additional_metadata: Option, param_file: Option, context: &C) -> Box> { let mut uri = format!( - "{}/v2/pet/{petId}/uploadImage", - self.base_path, petId=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) + "{}/v2/pet/{pet_id}/uploadImage", + self.base_path, pet_id=utf8_percent_encode(¶m_pet_id.to_string(), ID_ENCODE_SET) ); let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned()); 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 6adb604b9e4..8623560766a 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 @@ -86,6 +86,12 @@ pub enum FakeOuterStringSerializeResponse { (String) } +#[derive(Debug, PartialEq)] +pub enum HyphenParamResponse { + /// Success + Success +} + #[derive(Debug, PartialEq)] pub enum TestBodyWithQueryParamsResponse { /// Success @@ -334,6 +340,9 @@ pub trait Api { fn fake_outer_string_serialize(&self, body: Option, context: &C) -> Box>; + fn hyphen_param(&self, hyphen_param: String, context: &C) -> Box>; + + fn test_body_with_query_params(&self, query: String, body: models::User, context: &C) -> Box>; /// To test \"client\" model @@ -435,6 +444,9 @@ pub trait ApiNoContext { fn fake_outer_string_serialize(&self, body: Option) -> Box>; + fn hyphen_param(&self, hyphen_param: String) -> Box>; + + fn test_body_with_query_params(&self, query: String, body: models::User) -> Box>; /// To test \"client\" model @@ -557,6 +569,11 @@ impl<'a, T: Api, C> ApiNoContext for ContextWrapper<'a, T, C> { } + fn hyphen_param(&self, hyphen_param: String) -> Box> { + self.api().hyphen_param(hyphen_param, &self.context()) + } + + fn test_body_with_query_params(&self, query: String, body: models::User) -> Box> { self.api().test_body_with_query_params(query, body, &self.context()) } diff --git a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs index 79556f3ae9d..63a6b67c601 100644 --- a/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs @@ -45,6 +45,7 @@ use {Api, FakeOuterCompositeSerializeResponse, FakeOuterNumberSerializeResponse, FakeOuterStringSerializeResponse, + HyphenParamResponse, TestBodyWithQueryParamsResponse, TestClientModelResponse, TestEndpointParametersResponse, @@ -88,6 +89,7 @@ mod paths { r"^/v2/another-fake/dummy$", r"^/v2/fake$", r"^/v2/fake/body-with-query-params$", + r"^/v2/fake/hyphenParam/(?P[^/?#]*)$", r"^/v2/fake/inline-additionalProperties$", r"^/v2/fake/jsonFormData$", r"^/v2/fake/outer/boolean$", @@ -98,8 +100,8 @@ mod paths { r"^/v2/pet$", r"^/v2/pet/findByStatus$", r"^/v2/pet/findByTags$", - r"^/v2/pet/(?P[^/?#]*)$", - r"^/v2/pet/(?P[^/?#]*)/uploadImage$", + r"^/v2/pet/(?P[^/?#]*)$", + r"^/v2/pet/(?P[^/?#]*)/uploadImage$", r"^/v2/store/inventory$", r"^/v2/store/order$", r"^/v2/store/order/(?P[^/?#]*)$", @@ -114,36 +116,40 @@ mod paths { pub static ID_ANOTHER_FAKE_DUMMY: usize = 0; pub static ID_FAKE: usize = 1; pub static ID_FAKE_BODY_WITH_QUERY_PARAMS: usize = 2; - pub static ID_FAKE_INLINE_ADDITIONALPROPERTIES: usize = 3; - pub static ID_FAKE_JSONFORMDATA: usize = 4; - pub static ID_FAKE_OUTER_BOOLEAN: usize = 5; - pub static ID_FAKE_OUTER_COMPOSITE: usize = 6; - pub static ID_FAKE_OUTER_NUMBER: usize = 7; - pub static ID_FAKE_OUTER_STRING: usize = 8; - pub static ID_FAKE_CLASSNAME_TEST: usize = 9; - pub static ID_PET: usize = 10; - pub static ID_PET_FINDBYSTATUS: usize = 11; - pub static ID_PET_FINDBYTAGS: usize = 12; - pub static ID_PET_PETID: usize = 13; + pub static ID_FAKE_HYPHENPARAM_HYPHEN_PARAM: usize = 3; lazy_static! { - pub static ref REGEX_PET_PETID: regex::Regex = regex::Regex::new(r"^/v2/pet/(?P[^/?#]*)$").unwrap(); + pub static ref REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM: regex::Regex = regex::Regex::new(r"^/v2/fake/hyphenParam/(?P[^/?#]*)$").unwrap(); } - pub static ID_PET_PETID_UPLOADIMAGE: usize = 14; + pub static ID_FAKE_INLINE_ADDITIONALPROPERTIES: usize = 4; + pub static ID_FAKE_JSONFORMDATA: usize = 5; + pub static ID_FAKE_OUTER_BOOLEAN: usize = 6; + pub static ID_FAKE_OUTER_COMPOSITE: usize = 7; + pub static ID_FAKE_OUTER_NUMBER: usize = 8; + pub static ID_FAKE_OUTER_STRING: usize = 9; + pub static ID_FAKE_CLASSNAME_TEST: usize = 10; + pub static ID_PET: usize = 11; + pub static ID_PET_FINDBYSTATUS: usize = 12; + pub static ID_PET_FINDBYTAGS: usize = 13; + pub static ID_PET_PETID: usize = 14; lazy_static! { - pub static ref REGEX_PET_PETID_UPLOADIMAGE: regex::Regex = regex::Regex::new(r"^/v2/pet/(?P[^/?#]*)/uploadImage$").unwrap(); + pub static ref REGEX_PET_PETID: regex::Regex = regex::Regex::new(r"^/v2/pet/(?P[^/?#]*)$").unwrap(); } - pub static ID_STORE_INVENTORY: usize = 15; - pub static ID_STORE_ORDER: usize = 16; - pub static ID_STORE_ORDER_ORDER_ID: usize = 17; + pub static ID_PET_PETID_UPLOADIMAGE: usize = 15; + lazy_static! { + pub static ref REGEX_PET_PETID_UPLOADIMAGE: regex::Regex = regex::Regex::new(r"^/v2/pet/(?P[^/?#]*)/uploadImage$").unwrap(); + } + pub static ID_STORE_INVENTORY: usize = 16; + pub static ID_STORE_ORDER: usize = 17; + pub static ID_STORE_ORDER_ORDER_ID: usize = 18; lazy_static! { pub static ref REGEX_STORE_ORDER_ORDER_ID: regex::Regex = regex::Regex::new(r"^/v2/store/order/(?P[^/?#]*)$").unwrap(); } - pub static ID_USER: usize = 18; - pub static ID_USER_CREATEWITHARRAY: usize = 19; - pub static ID_USER_CREATEWITHLIST: usize = 20; - pub static ID_USER_LOGIN: usize = 21; - pub static ID_USER_LOGOUT: usize = 22; - pub static ID_USER_USERNAME: usize = 23; + pub static ID_USER: usize = 19; + pub static ID_USER_CREATEWITHARRAY: usize = 20; + pub static ID_USER_CREATEWITHLIST: usize = 21; + pub static ID_USER_LOGIN: usize = 22; + pub static ID_USER_LOGOUT: usize = 23; + pub static ID_USER_USERNAME: usize = 24; lazy_static! { pub static ref REGEX_USER_USERNAME: regex::Regex = regex::Regex::new(r"^/v2/user/(?P[^/?#]*)$").unwrap(); } @@ -541,6 +547,55 @@ where ) as Box> }, + // HyphenParam - GET /fake/hyphenParam/{hyphen-param} + &hyper::Method::Get if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => { + // Path parameters + let path = uri.path().to_string(); + let path_params = + paths::REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM + .captures(&path) + .unwrap_or_else(|| + panic!("Path {} matched RE FAKE_HYPHENPARAM_HYPHEN_PARAM in set but failed match against \"{}\"", path, paths::REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM.as_str()) + ); + let param_hyphen_param = match percent_encoding::percent_decode(path_params["hyphen_param"].as_bytes()).decode_utf8() { + Ok(param_hyphen_param) => match param_hyphen_param.parse::() { + Ok(param_hyphen_param) => param_hyphen_param, + Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter hyphen-param: {:?}", e)))), + }, + Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["hyphen_param"])))) + }; + Box::new({ + {{ + Box::new(api_impl.hyphen_param(param_hyphen_param, &context) + .then(move |result| { + let mut response = Response::new(); + response.headers_mut().set(XSpanId((&context as &dyn Has).get().0.to_string())); + + match result { + Ok(rsp) => match rsp { + HyphenParamResponse::Success + + + => { + response.set_status(StatusCode::try_from(200).unwrap()); + + }, + }, + Err(_) => { + // Application code returned an error. This should not happen, as the implementation should + // return a valid response. + response.set_status(StatusCode::InternalServerError); + response.set_body("An internal error occurred"); + }, + } + + future::ok(response) + } + )) + }} + }) as Box> + }, + // TestBodyWithQueryParams - PUT /fake/body-with-query-params &hyper::Method::Put if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => { // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) @@ -1124,12 +1179,12 @@ where .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID.as_str()) ); - let param_pet_id = match percent_encoding::percent_decode(path_params["petId"].as_bytes()).decode_utf8() { + let param_pet_id = match percent_encoding::percent_decode(path_params["pet_id"].as_bytes()).decode_utf8() { Ok(param_pet_id) => match param_pet_id.parse::() { Ok(param_pet_id) => param_pet_id, Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter petId: {:?}", e)))), }, - Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["petId"])))) + Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["pet_id"])))) }; // Header parameters header! { (RequestApiKey, "api_key") => [String] } @@ -1343,12 +1398,12 @@ where .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID.as_str()) ); - let param_pet_id = match percent_encoding::percent_decode(path_params["petId"].as_bytes()).decode_utf8() { + let param_pet_id = match percent_encoding::percent_decode(path_params["pet_id"].as_bytes()).decode_utf8() { Ok(param_pet_id) => match param_pet_id.parse::() { Ok(param_pet_id) => param_pet_id, Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter petId: {:?}", e)))), }, - Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["petId"])))) + Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["pet_id"])))) }; Box::new({ {{ @@ -1543,12 +1598,12 @@ where .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID.as_str()) ); - let param_pet_id = match percent_encoding::percent_decode(path_params["petId"].as_bytes()).decode_utf8() { + let param_pet_id = match percent_encoding::percent_decode(path_params["pet_id"].as_bytes()).decode_utf8() { Ok(param_pet_id) => match param_pet_id.parse::() { Ok(param_pet_id) => param_pet_id, Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter petId: {:?}", e)))), }, - Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["petId"])))) + Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["pet_id"])))) }; Box::new({ {{ @@ -1626,12 +1681,12 @@ where .unwrap_or_else(|| panic!("Path {} matched RE PET_PETID_UPLOADIMAGE in set but failed match against \"{}\"", path, paths::REGEX_PET_PETID_UPLOADIMAGE.as_str()) ); - let param_pet_id = match percent_encoding::percent_decode(path_params["petId"].as_bytes()).decode_utf8() { + let param_pet_id = match percent_encoding::percent_decode(path_params["pet_id"].as_bytes()).decode_utf8() { Ok(param_pet_id) => match param_pet_id.parse::() { Ok(param_pet_id) => param_pet_id, Err(e) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't parse path parameter petId: {:?}", e)))), }, - Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["petId"])))) + Err(_) => return Box::new(future::ok(Response::new().with_status(StatusCode::BadRequest).with_body(format!("Couldn't percent-decode path parameter as UTF-8: {}", &path_params["pet_id"])))) }; // Form Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for @@ -2523,6 +2578,9 @@ impl RequestParser for ApiRequestParser { // FakeOuterStringSerialize - POST /fake/outer/string &hyper::Method::Post if path.matched(paths::ID_FAKE_OUTER_STRING) => Ok("FakeOuterStringSerialize"), + // HyphenParam - GET /fake/hyphenParam/{hyphen-param} + &hyper::Method::Get if path.matched(paths::ID_FAKE_HYPHENPARAM_HYPHEN_PARAM) => Ok("HyphenParam"), + // TestBodyWithQueryParams - PUT /fake/body-with-query-params &hyper::Method::Put if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => Ok("TestBodyWithQueryParams"),