[rust-server] Re-instate ApiRequestParser (#1388)

* Re-instate ApiRequestParser

It turns out I was over-eager when removing file support and accidentally deleted some code that should have been kept. See https://github.com/OpenAPITools/openapi-generator/pull/547/files#diff-684007b298ee5998fa30732c261ea2fcL469.

* Don't do html escaping of parameters
This commit is contained in:
Benjamin Gill 2018-11-09 11:23:59 +00:00 committed by GitHub
parent 1522855915
commit 4742f0086b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 141 additions and 0 deletions

View File

@ -380,3 +380,17 @@ impl<T, C> Clone for Service<T, C>
}
}
}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl RequestParser for ApiRequestParser {
fn parse_operation_id(request: &Request) -> Result<&'static str, ()> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}
// {{{operationId}}} - {{{httpMethod}}} {{{path}}}
&hyper::Method::{{{vendorExtensions.HttpMethod}}} if path.matched(paths::ID_{{{vendorExtensions.PATH_ID}}}) => Ok("{{{operationId}}}"),
{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} _ => Err(()),
}
}
}

View File

@ -2949,3 +2949,110 @@ impl<T, C> Clone for Service<T, C>
}
}
}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl RequestParser for ApiRequestParser {
fn parse_operation_id(request: &Request) -> Result<&'static str, ()> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// TestSpecialTags - PATCH /another-fake/dummy
&hyper::Method::Patch if path.matched(paths::ID_ANOTHER_FAKE_DUMMY) => Ok("TestSpecialTags"),
// FakeOuterBooleanSerialize - POST /fake/outer/boolean
&hyper::Method::Post if path.matched(paths::ID_FAKE_OUTER_BOOLEAN) => Ok("FakeOuterBooleanSerialize"),
// FakeOuterCompositeSerialize - POST /fake/outer/composite
&hyper::Method::Post if path.matched(paths::ID_FAKE_OUTER_COMPOSITE) => Ok("FakeOuterCompositeSerialize"),
// FakeOuterNumberSerialize - POST /fake/outer/number
&hyper::Method::Post if path.matched(paths::ID_FAKE_OUTER_NUMBER) => Ok("FakeOuterNumberSerialize"),
// FakeOuterStringSerialize - POST /fake/outer/string
&hyper::Method::Post if path.matched(paths::ID_FAKE_OUTER_STRING) => Ok("FakeOuterStringSerialize"),
// TestBodyWithQueryParams - PUT /fake/body-with-query-params
&hyper::Method::Put if path.matched(paths::ID_FAKE_BODY_WITH_QUERY_PARAMS) => Ok("TestBodyWithQueryParams"),
// TestClientModel - PATCH /fake
&hyper::Method::Patch if path.matched(paths::ID_FAKE) => Ok("TestClientModel"),
// TestEndpointParameters - POST /fake
&hyper::Method::Post if path.matched(paths::ID_FAKE) => Ok("TestEndpointParameters"),
// TestEnumParameters - GET /fake
&hyper::Method::Get if path.matched(paths::ID_FAKE) => Ok("TestEnumParameters"),
// TestInlineAdditionalProperties - POST /fake/inline-additionalProperties
&hyper::Method::Post if path.matched(paths::ID_FAKE_INLINE_ADDITIONALPROPERTIES) => Ok("TestInlineAdditionalProperties"),
// TestJsonFormData - GET /fake/jsonFormData
&hyper::Method::Get if path.matched(paths::ID_FAKE_JSONFORMDATA) => Ok("TestJsonFormData"),
// TestClassname - PATCH /fake_classname_test
&hyper::Method::Patch if path.matched(paths::ID_FAKE_CLASSNAME_TEST) => Ok("TestClassname"),
// AddPet - POST /pet
&hyper::Method::Post if path.matched(paths::ID_PET) => Ok("AddPet"),
// DeletePet - DELETE /pet/{petId}
&hyper::Method::Delete if path.matched(paths::ID_PET_PETID) => Ok("DeletePet"),
// FindPetsByStatus - GET /pet/findByStatus
&hyper::Method::Get if path.matched(paths::ID_PET_FINDBYSTATUS) => Ok("FindPetsByStatus"),
// FindPetsByTags - GET /pet/findByTags
&hyper::Method::Get if path.matched(paths::ID_PET_FINDBYTAGS) => Ok("FindPetsByTags"),
// GetPetById - GET /pet/{petId}
&hyper::Method::Get if path.matched(paths::ID_PET_PETID) => Ok("GetPetById"),
// UpdatePet - PUT /pet
&hyper::Method::Put if path.matched(paths::ID_PET) => Ok("UpdatePet"),
// UpdatePetWithForm - POST /pet/{petId}
&hyper::Method::Post if path.matched(paths::ID_PET_PETID) => Ok("UpdatePetWithForm"),
// UploadFile - POST /pet/{petId}/uploadImage
&hyper::Method::Post if path.matched(paths::ID_PET_PETID_UPLOADIMAGE) => Ok("UploadFile"),
// DeleteOrder - DELETE /store/order/{order_id}
&hyper::Method::Delete if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Ok("DeleteOrder"),
// GetInventory - GET /store/inventory
&hyper::Method::Get if path.matched(paths::ID_STORE_INVENTORY) => Ok("GetInventory"),
// GetOrderById - GET /store/order/{order_id}
&hyper::Method::Get if path.matched(paths::ID_STORE_ORDER_ORDER_ID) => Ok("GetOrderById"),
// PlaceOrder - POST /store/order
&hyper::Method::Post if path.matched(paths::ID_STORE_ORDER) => Ok("PlaceOrder"),
// CreateUser - POST /user
&hyper::Method::Post if path.matched(paths::ID_USER) => Ok("CreateUser"),
// CreateUsersWithArrayInput - POST /user/createWithArray
&hyper::Method::Post if path.matched(paths::ID_USER_CREATEWITHARRAY) => Ok("CreateUsersWithArrayInput"),
// CreateUsersWithListInput - POST /user/createWithList
&hyper::Method::Post if path.matched(paths::ID_USER_CREATEWITHLIST) => Ok("CreateUsersWithListInput"),
// DeleteUser - DELETE /user/{username}
&hyper::Method::Delete if path.matched(paths::ID_USER_USERNAME) => Ok("DeleteUser"),
// GetUserByName - GET /user/{username}
&hyper::Method::Get if path.matched(paths::ID_USER_USERNAME) => Ok("GetUserByName"),
// LoginUser - GET /user/login
&hyper::Method::Get if path.matched(paths::ID_USER_LOGIN) => Ok("LoginUser"),
// LogoutUser - GET /user/logout
&hyper::Method::Get if path.matched(paths::ID_USER_LOGOUT) => Ok("LogoutUser"),
// UpdateUser - PUT /user/{username}
&hyper::Method::Put if path.matched(paths::ID_USER_USERNAME) => Ok("UpdateUser"),
_ => Err(()),
}
}
}

View File

@ -334,3 +334,23 @@ impl<T, C> Clone for Service<T, C>
}
}
}
/// Request parser for `Api`.
pub struct ApiRequestParser;
impl RequestParser for ApiRequestParser {
fn parse_operation_id(request: &Request) -> Result<&'static str, ()> {
let path = paths::GLOBAL_REGEX_SET.matches(request.uri().path());
match request.method() {
// DummyGet - GET /dummy
&hyper::Method::Get if path.matched(paths::ID_DUMMY) => Ok("DummyGet"),
// DummyPut - PUT /dummy
&hyper::Method::Put if path.matched(paths::ID_DUMMY) => Ok("DummyPut"),
// HtmlPost - POST /html
&hyper::Method::Post if path.matched(paths::ID_HTML) => Ok("HtmlPost"),
_ => Err(()),
}
}
}