From db10bba1e39d64f974e9219dbbba7a5e49c53759 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 10 Jun 2020 16:23:15 +0800 Subject: [PATCH] Update rust config (#6600) * update rust config * update rust reqwest async sample --- .../{other => }/rust-hyper-petstore.yaml | 0 .../rust-reqwest-petstore-async.yaml | 3 +- .../{other => }/rust-reqwest-petstore.yaml | 0 .../reqwest/petstore-async/src/apis/mod.rs | 18 +++ .../petstore-async/src/apis/pet_api.rs | 110 ++++++++++++++++-- .../petstore-async/src/apis/store_api.rs | 40 ++++++- .../petstore-async/src/apis/user_api.rs | 94 +++++++++++++-- 7 files changed, 244 insertions(+), 21 deletions(-) rename bin/configs/{other => }/rust-hyper-petstore.yaml (100%) rename bin/configs/{other => }/rust-reqwest-petstore-async.yaml (84%) rename bin/configs/{other => }/rust-reqwest-petstore.yaml (100%) diff --git a/bin/configs/other/rust-hyper-petstore.yaml b/bin/configs/rust-hyper-petstore.yaml similarity index 100% rename from bin/configs/other/rust-hyper-petstore.yaml rename to bin/configs/rust-hyper-petstore.yaml diff --git a/bin/configs/other/rust-reqwest-petstore-async.yaml b/bin/configs/rust-reqwest-petstore-async.yaml similarity index 84% rename from bin/configs/other/rust-reqwest-petstore-async.yaml rename to bin/configs/rust-reqwest-petstore-async.yaml index 0fb53b47d284..70b191533ef3 100644 --- a/bin/configs/other/rust-reqwest-petstore-async.yaml +++ b/bin/configs/rust-reqwest-petstore-async.yaml @@ -4,5 +4,6 @@ library: reqwest inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml templateDir: modules/openapi-generator/src/main/resources/rust additionalProperties: - supportAsync: "true" + supportAsync: true packageName: petstore-reqwest-async + useSingleRequestParameter: true diff --git a/bin/configs/other/rust-reqwest-petstore.yaml b/bin/configs/rust-reqwest-petstore.yaml similarity index 100% rename from bin/configs/other/rust-reqwest-petstore.yaml rename to bin/configs/rust-reqwest-petstore.yaml diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs index 2bab29983bc3..898d84e1e89c 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/mod.rs @@ -32,26 +32,44 @@ pub fn urlencode>(s: T) -> String { mod pet_api; pub use self::pet_api::{ add_pet }; +pub use self::pet_api::AddPetParams as PetApiAddPetParams; pub use self::pet_api::{ delete_pet }; +pub use self::pet_api::DeletePetParams as PetApiDeletePetParams; pub use self::pet_api::{ find_pets_by_status }; +pub use self::pet_api::FindPetsByStatusParams as PetApiFindPetsByStatusParams; pub use self::pet_api::{ find_pets_by_tags }; +pub use self::pet_api::FindPetsByTagsParams as PetApiFindPetsByTagsParams; pub use self::pet_api::{ get_pet_by_id }; +pub use self::pet_api::GetPetByIdParams as PetApiGetPetByIdParams; pub use self::pet_api::{ update_pet }; +pub use self::pet_api::UpdatePetParams as PetApiUpdatePetParams; pub use self::pet_api::{ update_pet_with_form }; +pub use self::pet_api::UpdatePetWithFormParams as PetApiUpdatePetWithFormParams; pub use self::pet_api::{ upload_file }; +pub use self::pet_api::UploadFileParams as PetApiUploadFileParams; mod store_api; pub use self::store_api::{ delete_order }; +pub use self::store_api::DeleteOrderParams as StoreApiDeleteOrderParams; pub use self::store_api::{ get_inventory }; pub use self::store_api::{ get_order_by_id }; +pub use self::store_api::GetOrderByIdParams as StoreApiGetOrderByIdParams; pub use self::store_api::{ place_order }; +pub use self::store_api::PlaceOrderParams as StoreApiPlaceOrderParams; mod user_api; pub use self::user_api::{ create_user }; +pub use self::user_api::CreateUserParams as UserApiCreateUserParams; pub use self::user_api::{ create_users_with_array_input }; +pub use self::user_api::CreateUsersWithArrayInputParams as UserApiCreateUsersWithArrayInputParams; pub use self::user_api::{ create_users_with_list_input }; +pub use self::user_api::CreateUsersWithListInputParams as UserApiCreateUsersWithListInputParams; pub use self::user_api::{ delete_user }; +pub use self::user_api::DeleteUserParams as UserApiDeleteUserParams; pub use self::user_api::{ get_user_by_name }; +pub use self::user_api::GetUserByNameParams as UserApiGetUserByNameParams; pub use self::user_api::{ login_user }; +pub use self::user_api::LoginUserParams as UserApiLoginUserParams; pub use self::user_api::{ logout_user }; pub use self::user_api::{ update_user }; +pub use self::user_api::UpdateUserParams as UserApiUpdateUserParams; pub mod configuration; diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index 8dfe56d1f1f4..f43db5ae5806 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -17,8 +17,76 @@ use reqwest; use super::{Error, configuration}; +/// struct for passing parameters to the method `add_pet` +#[derive(Clone, Debug)] +pub struct AddPetParams { + /// Pet object that needs to be added to the store + pub body: crate::models::Pet +} + +/// struct for passing parameters to the method `delete_pet` +#[derive(Clone, Debug)] +pub struct DeletePetParams { + /// Pet id to delete + pub pet_id: i64, + pub api_key: Option +} + +/// struct for passing parameters to the method `find_pets_by_status` +#[derive(Clone, Debug)] +pub struct FindPetsByStatusParams { + /// Status values that need to be considered for filter + pub status: Vec +} + +/// struct for passing parameters to the method `find_pets_by_tags` +#[derive(Clone, Debug)] +pub struct FindPetsByTagsParams { + /// Tags to filter by + pub tags: Vec +} + +/// struct for passing parameters to the method `get_pet_by_id` +#[derive(Clone, Debug)] +pub struct GetPetByIdParams { + /// ID of pet to return + pub pet_id: i64 +} + +/// struct for passing parameters to the method `update_pet` +#[derive(Clone, Debug)] +pub struct UpdatePetParams { + /// Pet object that needs to be added to the store + pub body: crate::models::Pet +} + +/// struct for passing parameters to the method `update_pet_with_form` +#[derive(Clone, Debug)] +pub struct UpdatePetWithFormParams { + /// ID of pet that needs to be updated + pub pet_id: i64, + /// Updated name of the pet + pub name: Option, + /// Updated status of the pet + pub status: Option +} + +/// struct for passing parameters to the method `upload_file` +#[derive(Clone, Debug)] +pub struct UploadFileParams { + /// ID of pet to update + pub pet_id: i64, + /// Additional data to pass to server + pub additional_metadata: Option, + /// file to upload + pub file: Option +} + + + pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result<(), Error> { + // unbox the parameters + let body = params.body; - pub async fn add_pet(configuration: &configuration::Configuration, body: crate::models::Pet) -> Result<(), Error> { let client = &configuration.client; let uri_str = format!("{}/pet", configuration.base_path); @@ -37,7 +105,11 @@ use super::{Error, configuration}; Ok(()) } - pub async fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api_key: Option<&str>) -> Result<(), Error> { + pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result<(), Error> { + // unbox the parameters + let pet_id = params.pet_id; + let api_key = params.api_key; + let client = &configuration.client; let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); @@ -58,7 +130,10 @@ use super::{Error, configuration}; Ok(()) } - pub async fn find_pets_by_status(configuration: &configuration::Configuration, status: Vec) -> Result, Error> { + pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { + // unbox the parameters + let status = params.status; + let client = &configuration.client; let uri_str = format!("{}/pet/findByStatus", configuration.base_path); @@ -76,7 +151,10 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::>().await?) } - pub async fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec) -> Result, Error> { + pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { + // unbox the parameters + let tags = params.tags; + let client = &configuration.client; let uri_str = format!("{}/pet/findByTags", configuration.base_path); @@ -94,7 +172,10 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::>().await?) } - pub async fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result { + pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result { + // unbox the parameters + let pet_id = params.pet_id; + let client = &configuration.client; let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); @@ -116,7 +197,10 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::().await?) } - pub async fn update_pet(configuration: &configuration::Configuration, body: crate::models::Pet) -> Result<(), Error> { + pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result<(), Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; let uri_str = format!("{}/pet", configuration.base_path); @@ -135,7 +219,12 @@ use super::{Error, configuration}; Ok(()) } - pub async fn update_pet_with_form(configuration: &configuration::Configuration, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> { + pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result<(), Error> { + // unbox the parameters + let pet_id = params.pet_id; + let name = params.name; + let status = params.status; + let client = &configuration.client; let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=pet_id); @@ -161,7 +250,12 @@ use super::{Error, configuration}; Ok(()) } - pub async fn upload_file(configuration: &configuration::Configuration, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result { + pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result { + // unbox the parameters + let pet_id = params.pet_id; + let additional_metadata = params.additional_metadata; + let file = params.file; + let client = &configuration.client; let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=pet_id); diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index d9ab07295ec6..2ccebe8022f6 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -17,8 +17,32 @@ use reqwest; use super::{Error, configuration}; +/// struct for passing parameters to the method `delete_order` +#[derive(Clone, Debug)] +pub struct DeleteOrderParams { + /// ID of the order that needs to be deleted + pub order_id: String +} + +/// struct for passing parameters to the method `get_order_by_id` +#[derive(Clone, Debug)] +pub struct GetOrderByIdParams { + /// ID of pet that needs to be fetched + pub order_id: i64 +} + +/// struct for passing parameters to the method `place_order` +#[derive(Clone, Debug)] +pub struct PlaceOrderParams { + /// order placed for purchasing the pet + pub body: crate::models::Order +} + + + pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result<(), Error> { + // unbox the parameters + let order_id = params.order_id; - pub async fn delete_order(configuration: &configuration::Configuration, order_id: &str) -> Result<(), Error> { let client = &configuration.client; let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(order_id)); @@ -33,7 +57,9 @@ use super::{Error, configuration}; Ok(()) } - pub async fn get_inventory(configuration: &configuration::Configuration, ) -> Result<::std::collections::HashMap, Error> { + pub async fn get_inventory(configuration: &configuration::Configuration) -> Result<::std::collections::HashMap, Error> { + // unbox the parameters + let client = &configuration.client; let uri_str = format!("{}/store/inventory", configuration.base_path); @@ -55,7 +81,10 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::<::std::collections::HashMap>().await?) } - pub async fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result { + pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result { + // unbox the parameters + let order_id = params.order_id; + let client = &configuration.client; let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=order_id); @@ -69,7 +98,10 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::().await?) } - pub async fn place_order(configuration: &configuration::Configuration, body: crate::models::Order) -> Result { + pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result { + // unbox the parameters + let body = params.body; + let client = &configuration.client; let uri_str = format!("{}/store/order", configuration.base_path); diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index 618cca717893..ac3ec992d880 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -17,8 +17,64 @@ use reqwest; use super::{Error, configuration}; +/// struct for passing parameters to the method `create_user` +#[derive(Clone, Debug)] +pub struct CreateUserParams { + /// Created user object + pub body: crate::models::User +} + +/// struct for passing parameters to the method `create_users_with_array_input` +#[derive(Clone, Debug)] +pub struct CreateUsersWithArrayInputParams { + /// List of user object + pub body: Vec +} + +/// struct for passing parameters to the method `create_users_with_list_input` +#[derive(Clone, Debug)] +pub struct CreateUsersWithListInputParams { + /// List of user object + pub body: Vec +} + +/// struct for passing parameters to the method `delete_user` +#[derive(Clone, Debug)] +pub struct DeleteUserParams { + /// The name that needs to be deleted + pub username: String +} + +/// struct for passing parameters to the method `get_user_by_name` +#[derive(Clone, Debug)] +pub struct GetUserByNameParams { + /// The name that needs to be fetched. Use user1 for testing. + pub username: String +} + +/// struct for passing parameters to the method `login_user` +#[derive(Clone, Debug)] +pub struct LoginUserParams { + /// The user name for login + pub username: String, + /// The password for login in clear text + pub password: String +} + +/// struct for passing parameters to the method `update_user` +#[derive(Clone, Debug)] +pub struct UpdateUserParams { + /// name that need to be deleted + pub username: String, + /// Updated user object + pub body: crate::models::User +} + + + pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result<(), Error> { + // unbox the parameters + let body = params.body; - pub async fn create_user(configuration: &configuration::Configuration, body: crate::models::User) -> Result<(), Error> { let client = &configuration.client; let uri_str = format!("{}/user", configuration.base_path); @@ -34,7 +90,10 @@ use super::{Error, configuration}; Ok(()) } - pub async fn create_users_with_array_input(configuration: &configuration::Configuration, body: Vec) -> Result<(), Error> { + pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result<(), Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; let uri_str = format!("{}/user/createWithArray", configuration.base_path); @@ -50,7 +109,10 @@ use super::{Error, configuration}; Ok(()) } - pub async fn create_users_with_list_input(configuration: &configuration::Configuration, body: Vec) -> Result<(), Error> { + pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result<(), Error> { + // unbox the parameters + let body = params.body; + let client = &configuration.client; let uri_str = format!("{}/user/createWithList", configuration.base_path); @@ -66,7 +128,10 @@ use super::{Error, configuration}; Ok(()) } - pub async fn delete_user(configuration: &configuration::Configuration, username: &str) -> Result<(), Error> { + pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result<(), Error> { + // unbox the parameters + let username = params.username; + let client = &configuration.client; let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); @@ -81,7 +146,10 @@ use super::{Error, configuration}; Ok(()) } - pub async fn get_user_by_name(configuration: &configuration::Configuration, username: &str) -> Result { + pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result { + // unbox the parameters + let username = params.username; + let client = &configuration.client; let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username)); @@ -95,7 +163,11 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::().await?) } - pub async fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result { + pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result { + // unbox the parameters + let username = params.username; + let password = params.password; + let client = &configuration.client; let uri_str = format!("{}/user/login", configuration.base_path); @@ -111,7 +183,9 @@ use super::{Error, configuration}; Ok(client.execute(req).await?.error_for_status()?.json::().await?) } - pub async fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), Error> { + pub async fn logout_user(configuration: &configuration::Configuration) -> Result<(), Error> { + // unbox the parameters + let client = &configuration.client; let uri_str = format!("{}/user/logout", configuration.base_path); @@ -126,7 +200,11 @@ use super::{Error, configuration}; Ok(()) } - pub async fn update_user(configuration: &configuration::Configuration, username: &str, body: crate::models::User) -> Result<(), Error> { + pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result<(), Error> { + // unbox the parameters + let username = params.username; + let body = params.body; + let client = &configuration.client; let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(username));