github.com/emcfarlane/larking@v0.0.0-20220605172417-1704b45ee6c3/starlib/net/starlarkopenapi/testdata/swagger_test.star (about) 1 load("blob.star", "blob") 2 load("net/openapi.star", "openapi") 3 4 api = openapi.open(spec_var, client = client) 5 6 print(dir(api)) 7 8 bkt = blob.open("file://./testdata") 9 10 def test_openapi(t): 11 def find_available(t): 12 pets = api.pet.find_pets_by_status(status = ["available"]) 13 pets_by_id = {} 14 for pet in pets: 15 pets_by_id[pet.id] = pet 16 return pets_by_id 17 18 pets_available = t.run("find_pets", find_available) 19 ids = pets_available.keys() 20 first_id = ids[0] 21 print("pet", pets_available[first_id]) 22 23 def post_image(t): 24 filename = "pixel.jpg" 25 img = bkt.read_all(filename) 26 print("file", (filename, img)) 27 rsp = api.pet.post_pet_pet_id_upload_image(petId = first_id, file = (filename, img)) 28 print(rsp) 29 30 t.run("post_image", post_image) 31 32 def get_pet(t): 33 rsp = api.pet.get_pet_by_id(petId = first_id) 34 print(rsp) 35 36 t.run("get_pet", get_pet) 37 38 pet = pets_available[first_id] 39 40 def update_pet(t): 41 pet.name = "Sir " + pet.name 42 rsp = api.pet.update_pet(body = pet) 43 print(rsp) 44 45 t.run("update_pet", update_pet) 46 47 def delete_pet(t): 48 rsp = api.pet.delete_pet(petId = first_id) 49 print(rsp) 50 51 t.run("delete_pet", delete_pet)