use openapi_gen::openapi_client;
#[test]
fn petstore_from_url() {
openapi_client!(
"https://petstore3.swagger.io/api/v3/openapi.json",
"PetstoreApi"
);
let _api = PetstoreApi::new("https://petstore3.swagger.io/api/v3");
}
#[tokio::test]
async fn petstore_fetch_single_pet() {
openapi_client!(
"https://petstore3.swagger.io/api/v3/openapi.json",
"PetstoreApi"
);
let client = PetstoreApi::new("https://petstore3.swagger.io/api/v3");
match client.get_pet_by_id(1).await {
Ok(pet) => {
println!("Successfully fetched pet: {:?}", pet);
}
Err(e) => {
panic!("Failed to fetch pet by ID 1: {:?}", e);
}
}
}
#[tokio::test]
async fn petstore_fetch_available_pets() {
openapi_client!(
"https://petstore3.swagger.io/api/v3/openapi.json",
"PetstoreApi"
);
let client = PetstoreApi::new("https://petstore3.swagger.io/api/v3");
match client.find_pets_by_status("available".to_string()).await {
Ok(pets) => {
println!("Successfully fetched {} available pets", pets.len());
assert!(pets.len() > 0, "Expected at least some available pets");
}
Err(e) => {
panic!("Failed to fetch available pets: {:?}", e);
}
}
}