[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
This commit is contained in:
aandyl 2020-01-16 23:44:23 -08:00 committed by William Cheng
parent f48325ac45
commit 67d23fcf7e
12 changed files with 283 additions and 47 deletions

View File

@ -552,6 +552,16 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
Map<String, Schema> 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<paramName>[^/?#]*) 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("}", ""));

View File

@ -262,8 +262,8 @@ impl<F, C> Api<C> for Client<F> 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<dyn Future<Item={{{operationId}}}Response, Error=ApiError>> {
let mut uri = format!(
"{}{{{basePathWithoutHost}}}{{path}}",
self.base_path{{#pathParams}}, {{{baseName}}}=utf8_percent_encode(&param_{{{paramName}}}.to_string(), ID_ENCODE_SET){{/pathParams}}
"{}{{{basePathWithoutHost}}}{{#vendorExtensions}}{{pathFormatString}}{{/vendorExtensions}}",
self.base_path{{#pathParams}}, {{{paramName}}}=utf8_percent_encode(&param_{{{paramName}}}.to_string(), ID_ENCODE_SET){{/pathParams}}
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());

View File

@ -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}}

View File

@ -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

View File

@ -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 假端點 偽のエンドポイント 가짜 엔드 포인트

View File

@ -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:

View File

@ -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)

View File

@ -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<XSpanIdString>).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<XSpanIdString>).get().clone());
},
// Disabled because there's no example.
// Some("TestBodyWithQueryParams") => {
// let result = core.run(client.test_body_with_query_params("query_example".to_string(), ???));

View File

@ -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<C> Api<C> for Server<C> where C: Has<XSpanIdString>{
}
fn hyphen_param(&self, hyphen_param: String, context: &C) -> Box<dyn Future<Item=HyphenParamResponse, Error=ApiError>> {
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<dyn Future<Item=TestBodyWithQueryParamsResponse, Error=ApiError>> {
let context = context.clone();
println!("test_body_with_query_params(\"{}\", {:?}) - X-Span-ID: {:?}", query, body, context.get().0.clone());

View File

@ -49,6 +49,7 @@ use {Api,
FakeOuterCompositeSerializeResponse,
FakeOuterNumberSerializeResponse,
FakeOuterStringSerializeResponse,
HyphenParamResponse,
TestBodyWithQueryParamsResponse,
TestClientModelResponse,
TestEndpointParametersResponse,
@ -678,6 +679,67 @@ impl<F, C> Api<C> for Client<F> where
}
fn hyphen_param(&self, param_hyphen_param: String, context: &C) -> Box<dyn Future<Item=HyphenParamResponse, Error=ApiError>> {
let mut uri = format!(
"{}/v2/fake/hyphenParam/{hyphen_param}",
self.base_path, hyphen_param=utf8_percent_encode(&param_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<XSpanIdString>).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<dyn Future<Item=_, Error=_>>
},
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!("<Body was not UTF8: {:?}>", e)),
},
Err(e) => Cow::from(format!("<Failed to read body: {}>", e)),
})))
)
) as Box<dyn Future<Item=_, Error=_>>
}
}
}))
}
fn test_body_with_query_params(&self, param_query: String, param_body: models::User, context: &C) -> Box<dyn Future<Item=TestBodyWithQueryParamsResponse, Error=ApiError>> {
let mut uri = format!(
"{}/v2/fake/body-with-query-params",
@ -1310,8 +1372,8 @@ impl<F, C> Api<C> for Client<F> where
fn delete_pet(&self, param_pet_id: i64, param_api_key: Option<String>, context: &C) -> Box<dyn Future<Item=DeletePetResponse, Error=ApiError>> {
let mut uri = format!(
"{}/v2/pet/{petId}",
self.base_path, petId=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
"{}/v2/pet/{pet_id}",
self.base_path, pet_id=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());
@ -1577,8 +1639,8 @@ impl<F, C> Api<C> for Client<F> where
fn get_pet_by_id(&self, param_pet_id: i64, context: &C) -> Box<dyn Future<Item=GetPetByIdResponse, Error=ApiError>> {
let mut uri = format!(
"{}/v2/pet/{petId}",
self.base_path, petId=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
"{}/v2/pet/{pet_id}",
self.base_path, pet_id=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());
@ -1776,8 +1838,8 @@ impl<F, C> Api<C> for Client<F> where
fn update_pet_with_form(&self, param_pet_id: i64, param_name: Option<String>, param_status: Option<String>, context: &C) -> Box<dyn Future<Item=UpdatePetWithFormResponse, Error=ApiError>> {
let mut uri = format!(
"{}/v2/pet/{petId}",
self.base_path, petId=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
"{}/v2/pet/{pet_id}",
self.base_path, pet_id=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());
@ -1857,8 +1919,8 @@ impl<F, C> Api<C> for Client<F> where
fn upload_file(&self, param_pet_id: i64, param_additional_metadata: Option<String>, param_file: Option<swagger::ByteArray>, context: &C) -> Box<dyn Future<Item=UploadFileResponse, Error=ApiError>> {
let mut uri = format!(
"{}/v2/pet/{petId}/uploadImage",
self.base_path, petId=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
"{}/v2/pet/{pet_id}/uploadImage",
self.base_path, pet_id=utf8_percent_encode(&param_pet_id.to_string(), ID_ENCODE_SET)
);
let mut query_string = self::url::form_urlencoded::Serializer::new("".to_owned());

View File

@ -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<C> {
fn fake_outer_string_serialize(&self, body: Option<models::OuterString>, context: &C) -> Box<dyn Future<Item=FakeOuterStringSerializeResponse, Error=ApiError>>;
fn hyphen_param(&self, hyphen_param: String, context: &C) -> Box<dyn Future<Item=HyphenParamResponse, Error=ApiError>>;
fn test_body_with_query_params(&self, query: String, body: models::User, context: &C) -> Box<dyn Future<Item=TestBodyWithQueryParamsResponse, Error=ApiError>>;
/// To test \"client\" model
@ -435,6 +444,9 @@ pub trait ApiNoContext {
fn fake_outer_string_serialize(&self, body: Option<models::OuterString>) -> Box<dyn Future<Item=FakeOuterStringSerializeResponse, Error=ApiError>>;
fn hyphen_param(&self, hyphen_param: String) -> Box<dyn Future<Item=HyphenParamResponse, Error=ApiError>>;
fn test_body_with_query_params(&self, query: String, body: models::User) -> Box<dyn Future<Item=TestBodyWithQueryParamsResponse, Error=ApiError>>;
/// To test \"client\" model
@ -557,6 +569,11 @@ impl<'a, T: Api<C>, C> ApiNoContext for ContextWrapper<'a, T, C> {
}
fn hyphen_param(&self, hyphen_param: String) -> Box<dyn Future<Item=HyphenParamResponse, Error=ApiError>> {
self.api().hyphen_param(hyphen_param, &self.context())
}
fn test_body_with_query_params(&self, query: String, body: models::User) -> Box<dyn Future<Item=TestBodyWithQueryParamsResponse, Error=ApiError>> {
self.api().test_body_with_query_params(query, body, &self.context())
}

View File

@ -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<hyphen_param>[^/?#]*)$",
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<petId>[^/?#]*)$",
r"^/v2/pet/(?P<petId>[^/?#]*)/uploadImage$",
r"^/v2/pet/(?P<pet_id>[^/?#]*)$",
r"^/v2/pet/(?P<pet_id>[^/?#]*)/uploadImage$",
r"^/v2/store/inventory$",
r"^/v2/store/order$",
r"^/v2/store/order/(?P<order_id>[^/?#]*)$",
@ -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<petId>[^/?#]*)$").unwrap();
pub static ref REGEX_FAKE_HYPHENPARAM_HYPHEN_PARAM: regex::Regex = regex::Regex::new(r"^/v2/fake/hyphenParam/(?P<hyphen_param>[^/?#]*)$").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<petId>[^/?#]*)/uploadImage$").unwrap();
pub static ref REGEX_PET_PETID: regex::Regex = regex::Regex::new(r"^/v2/pet/(?P<pet_id>[^/?#]*)$").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<pet_id>[^/?#]*)/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<order_id>[^/?#]*)$").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<username>[^/?#]*)$").unwrap();
}
@ -541,6 +547,55 @@ where
) as Box<dyn Future<Item=Response, Error=Error>>
},
// 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::<String>() {
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<XSpanIdString>).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<dyn Future<Item=Response, Error=Error>>
},
// 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::<i64>() {
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::<i64>() {
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::<i64>() {
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::<i64>() {
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"),