#![allow(missing_docs, unused_variables, trivial_casts)] #[allow(unused_imports)] use futures::{future, Stream, stream}; #[allow(unused_imports)] use hvcg_governance_openapi_catholic_polity::{Api, ApiNoContext, Client, ContextWrapperExt, models, AddDeaneryResponse, DeleteDeaneryResponse, GetDeaneriesResponse, GetDeaneryByIdResponse, UpdateDeaneryResponse, AddDioceseResponse, DeleteDioceseResponse, GetDioceseByIdResponse, GetDiocesesResponse, UpdateDioceseResponse, AddInstituteResponse, DeleteInstituteResponse, GetInstituteByIdResponse, GetInstitutesResponse, UpdateInstituteResponse, AddParishResponse, DeleteParishResponse, GetParishByIdResponse, GetParishesResponse, UpdateParishResponse, AddProvinceResponse, DeleteProvinceResponse, GetProvinceByIdResponse, GetProvincesResponse, UpdateProvinceResponse, }; 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(&[ "DeleteDeanery", "GetDeaneries", "GetDeaneryById", "DeleteDiocese", "GetDioceseById", "GetDioceses", "DeleteInstitute", "GetInstituteById", "GetInstitutes", "AddParish", "DeleteParish", "GetParishById", "GetParishes", "UpdateParish", "AddProvince", "DeleteProvince", "GetProvinceById", "GetProvinces", "UpdateProvince", ]) .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("dev-sg.portal.hocvienconggiao.com") .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("AddDeanery") => { let result = rt.block_on(client.add_deanery( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("DeleteDeanery") => { let result = rt.block_on(client.delete_deanery( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetDeaneries") => { let result = rt.block_on(client.get_deaneries( Some(serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example")), Some("name_example".to_string()), Some(56), Some(56) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetDeaneryById") => { let result = rt.block_on(client.get_deanery_by_id( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, /* Disabled because there's no example. Some("UpdateDeanery") => { let result = rt.block_on(client.update_deanery( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example"), ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ /* Disabled because there's no example. Some("AddDiocese") => { let result = rt.block_on(client.add_diocese( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("DeleteDiocese") => { let result = rt.block_on(client.delete_diocese( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetDioceseById") => { let result = rt.block_on(client.get_diocese_by_id( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetDioceses") => { let result = rt.block_on(client.get_dioceses( Some(serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example")), None, Some("province_name_example".to_string()), Some("name_example".to_string()), Some("location_name_example".to_string()), Some("location_address_example".to_string()), Some("location_email_example".to_string()), Some("person_in_charge_example".to_string()), Some(&Vec::new()), Some(56), Some(56) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, /* Disabled because there's no example. Some("UpdateDiocese") => { let result = rt.block_on(client.update_diocese( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example"), ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ /* Disabled because there's no example. Some("AddInstitute") => { let result = rt.block_on(client.add_institute( ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("DeleteInstitute") => { let result = rt.block_on(client.delete_institute( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetInstituteById") => { let result = rt.block_on(client.get_institute_by_id( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetInstitutes") => { let result = rt.block_on(client.get_institutes( Some("name_example".to_string()), Some("location_name_example".to_string()), Some("location_address_example".to_string()), Some("location_email_example".to_string()), Some("person_in_charge_example".to_string()), Some(&Vec::new()), Some(56), Some(56) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, /* Disabled because there's no example. Some("UpdateInstitute") => { let result = rt.block_on(client.update_institute( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example"), ??? )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, */ Some("AddParish") => { let result = rt.block_on(client.add_parish( None )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("DeleteParish") => { let result = rt.block_on(client.delete_parish( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetParishById") => { let result = rt.block_on(client.get_parish_by_id( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetParishes") => { let result = rt.block_on(client.get_parishes( Some(serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example")), Some(serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example")), Some("name_example".to_string()), Some(56), Some(56) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("UpdateParish") => { let result = rt.block_on(client.update_parish( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example"), None )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("AddProvince") => { let result = rt.block_on(client.add_province( None )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("DeleteProvince") => { let result = rt.block_on(client.delete_province( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetProvinceById") => { let result = rt.block_on(client.get_province_by_id( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example") )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("GetProvinces") => { let result = rt.block_on(client.get_provinces( Some("name_example".to_string()), None, Some(56), Some(56) )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, Some("UpdateProvince") => { let result = rt.block_on(client.update_province( serde_json::from_str::(r#"38400000-8cf0-11bd-b23e-10b96e4ef00d"#).expect("Failed to parse JSON example"), None )); info!("{:?} (X-Span-ID: {:?})", result, (client.context() as &dyn Has).get().clone()); }, _ => { panic!("Invalid operation provided") } } }