Update rust config (#6600)

* update rust config

* update rust reqwest async sample
This commit is contained in:
William Cheng
2020-06-10 16:23:15 +08:00
committed by GitHub
parent a4d679f9e5
commit db10bba1e3
7 changed files with 244 additions and 21 deletions

View File

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

View File

@@ -32,26 +32,44 @@ pub fn urlencode<T: AsRef<str>>(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;

View File

@@ -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<String>
}
/// 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<String>
}
/// struct for passing parameters to the method `find_pets_by_tags`
#[derive(Clone, Debug)]
pub struct FindPetsByTagsParams {
/// Tags to filter by
pub tags: Vec<String>
}
/// 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<String>,
/// Updated status of the pet
pub status: Option<String>
}
/// 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<String>,
/// file to upload
pub file: Option<std::path::PathBuf>
}
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<String>) -> Result<Vec<crate::models::Pet>, Error> {
pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result<Vec<crate::models::Pet>, 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::<Vec<crate::models::Pet>>().await?)
}
pub async fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec<String>) -> Result<Vec<crate::models::Pet>, Error> {
pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result<Vec<crate::models::Pet>, 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::<Vec<crate::models::Pet>>().await?)
}
pub async fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result<crate::models::Pet, Error> {
pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result<crate::models::Pet, Error> {
// 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::<crate::models::Pet>().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<std::path::PathBuf>) -> Result<crate::models::ApiResponse, Error> {
pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result<crate::models::ApiResponse, Error> {
// 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);

View File

@@ -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<String, i32>, Error> {
pub async fn get_inventory(configuration: &configuration::Configuration) -> Result<::std::collections::HashMap<String, i32>, 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<String, i32>>().await?)
}
pub async fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result<crate::models::Order, Error> {
pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result<crate::models::Order, Error> {
// 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::<crate::models::Order>().await?)
}
pub async fn place_order(configuration: &configuration::Configuration, body: crate::models::Order) -> Result<crate::models::Order, Error> {
pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result<crate::models::Order, Error> {
// unbox the parameters
let body = params.body;
let client = &configuration.client;
let uri_str = format!("{}/store/order", configuration.base_path);

View File

@@ -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<crate::models::User>
}
/// 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<crate::models::User>
}
/// 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<crate::models::User>) -> 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<crate::models::User>) -> 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<crate::models::User, Error> {
pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result<crate::models::User, 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));
@@ -95,7 +163,11 @@ use super::{Error, configuration};
Ok(client.execute(req).await?.error_for_status()?.json::<crate::models::User>().await?)
}
pub async fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result<String, Error> {
pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result<String, Error> {
// 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::<String>().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));