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 e635d9432c..887d1e468f 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 @@ -380,3 +380,17 @@ impl Clone for Service } } } + +/// 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(()), + } + } +} 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 8366ae215e..ca064ca7ef 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 @@ -2949,3 +2949,110 @@ impl Clone for Service } } } + +/// 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(()), + } + } +} diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs index cec0ed8e38..c436af8021 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs @@ -334,3 +334,23 @@ impl Clone for Service } } } + +/// 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(()), + } + } +}