github.com/emcfarlane/larking@v0.0.0-20220605172417-1704b45ee6c3/starlib/net/starlarkopenapi/testdata/example_pets.star (about) 1 load("http.star", "http") 2 load("openapi.star", "openapi") 3 4 spec_var = "https://petstore.swagger.io/v2/swagger.json" 5 6 # clients can be customized to alter the request or response. 7 # This takes a request and adds basic_auth, it also logs the requests. 8 def client_do(req): 9 print(req) # <request GET https://petstore.swagger.io/v2/pet/findByStatus?status=available> 10 req.basic_auth = ("username", "password") # encodes basic auth 11 print(req.header) # map[Accepts:[application/json] Authorization:[Basic dXNlcm5hbWU6cGFzc3dvcmQ=] Content-Type:[]] 12 13 # use the default client as the transport. 14 rsp = http.default_client.do(req) 15 print(rsp) # <response 200 OK> 16 return rsp 17 18 client = http.client(client_do) 19 20 api = openapi.open(spec_var, client = client) 21 22 print("api", api) # api <client "https://petstore.swagger.io/v2/swagger.json"> 23 24 for svc in dir(api): 25 print(svc, [m for m in dir(getattr(api, svc))]) 26 27 # pet ["add_pet", "delete_pet", "find_pets_by_status", "find_pets_by_tags", "get_pet_by_id", "update_pet", "update_pet_with_form", "upload_file"] 28 # store ["delete_order", "get_inventory", "get_order_by_id", "place_order"] 29 # user ["create_user", "create_users_with_array_input", "create_users_with_list_input", "delete_user", "get_user_by_name", "login_user", "logout_user", "update_user"] 30 31 pets = api.pet.find_pets_by_status(status = ["available"]) 32 print("%d pets available" % len(pets)) # 573 pets available