#![allow(missing_docs, unused_variables, trivial_casts)] #[allow(unused_imports)] use futures::{future, Stream, stream}; #[allow(unused_imports)] use hvcg_example_openapi_entity::{Api, ApiNoContext, Client, ContextWrapperExt, models, AddPetResponse, DeletePetResponse, FindPetsByStatusResponse, FindPetsByTagsResponse, GetPetByIdResponse, UpdatePetResponse, UpdatePetWithFormResponse, UploadFileResponse, DeleteOrderResponse, GetInventoryResponse, GetOrderByIdResponse, PlaceOrderResponse, CreateUserResponse, CreateUsersWithArrayInputResponse, CreateUsersWithListInputResponse, DeleteUserResponse, GetUserByNameResponse, LoginUserResponse, LogoutUserResponse, UpdateUserResponse, }; use clap::{App, Arg}; #[allow(unused_imports)] use log::info; // swagger::Has may be unused if there are no examples #[allow(unused_imports)] use swagger::{AuthData, ContextBuilder, EmptyContext, Has, Push, XSpanIdString}; type ClientContext = swagger::make_context_ty!(ContextBuilder, EmptyContext, Option, XSpanIdString); // rt may be unused if there are no examples #[allow(unused_mut)] fn main() { env_logger::init(); let matches = App::new("client") .arg(Arg::with_name("operation") .help("Sets the operation to run") .possible_values(&[ "DeletePet", "FindPetsByStatus", "FindPetsByTags", "GetPetById", "UpdatePetWithForm", "UploadFile", "DeleteOrder", "GetInventory", "GetOrderById", "CreateUsersWithArrayInput", "CreateUsersWithListInput", "DeleteUser", "GetUserByName", "LoginUser", "LogoutUser", ]) .required(true) .index(1)) .arg(Arg::with_name("https") .long("https") .help("Whether to use HTTPS or not")) .arg(Arg::with_name("host") .long("host") .takes_value(true) .default_value("petstore.swagger.io") .help("Hostname to contact")) .arg(Arg::with_name("port") .long("port") .takes_value(true) .default_value("8080") .help("Port to contact")) .get_matches(); let is_https = matches.is_present("https"); let base_url = format!("{}://{}:{}", if is_https { "https" } else { "http" }, matches.value_of("host").unwrap(), matches.value_of("port").unwrap()); let context: ClientContext = swagger::make_context!(ContextBuilder, EmptyContext, None as Option, XSpanIdString::default()); let mut client : Box> = if matches.is_present("https") { // Using Simple HTTPS let client = Box::new(Client::try_new_https(&base_url) .expect("Failed to create HTTPS client")); Box::new(client.with_context(context)) } else { // Using HTTP let client = Box::new(Client::try_new_http( &base_url) .expect("Failed to create HTTP client")); Box::new(client.with_context(context)) }; let mut rt = tokio::runtime::Runtime::new().unwrap(); match matches.value_of("operation") { /* Disabled because there's no example. Some("AddPet") => { let result = rt.block_on(client.add_pet( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("DeletePet") => { let result = rt.block_on(client.delete_pet( 789, Some("api_key_example".to_string()) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("FindPetsByStatus") => { let result = rt.block_on(client.find_pets_by_status( &Vec::new() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("FindPetsByTags") => { let result = rt.block_on(client.find_pets_by_tags( &Vec::new() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetPetById") => { let result = rt.block_on(client.get_pet_by_id( 789 )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, /* Disabled because there's no example. Some("UpdatePet") => { let result = rt.block_on(client.update_pet( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("UpdatePetWithForm") => { let result = rt.block_on(client.update_pet_with_form( 789, Some("name_example".to_string()), Some("status_example".to_string()) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("UploadFile") => { let result = rt.block_on(client.upload_file( 789, Some("additional_metadata_example".to_string()), Some(swagger::ByteArray(Vec::from("BINARY_DATA_HERE"))) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("DeleteOrder") => { let result = rt.block_on(client.delete_order( "order_id_example".to_string() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetInventory") => { let result = rt.block_on(client.get_inventory( )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetOrderById") => { let result = rt.block_on(client.get_order_by_id( 789 )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, /* Disabled because there's no example. Some("PlaceOrder") => { let result = rt.block_on(client.place_order( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ /* Disabled because there's no example. Some("CreateUser") => { let result = rt.block_on(client.create_user( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("CreateUsersWithArrayInput") => { let result = rt.block_on(client.create_users_with_array_input( &Vec::new() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("CreateUsersWithListInput") => { let result = rt.block_on(client.create_users_with_list_input( &Vec::new() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("DeleteUser") => { let result = rt.block_on(client.delete_user( "username_example".to_string() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetUserByName") => { let result = rt.block_on(client.get_user_by_name( "username_example".to_string() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("LoginUser") => { let result = rt.block_on(client.login_user( "username_example".to_string(), "password_example".to_string() )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("LogoutUser") => { let result = rt.block_on(client.logout_user( )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, /* Disabled because there's no example. Some("UpdateUser") => { let result = rt.block_on(client.update_user( "username_example".to_string(), ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ _ => { panic!("Invalid operation provided") } } }