requests-openapi
requests-openapi copied to clipboard
Any ideas about how to handle different API calls with different auth configuration?
Seems currently we can only set requestor auth configurations for all APIs, any ideas about how to handle different API calls with different auth configuration?
import requests_openapi
# load spec from url
c = requests_openapi.Client().load_spec_from_url("https://raw.githubusercontent.com/master/examples/v3.0/petstore.yaml")
# custom session for auth or others
c.requestor # a instance of requests.Session, see https://requests.readthedocs.io/en/latest/user/advanced/#session-objects
# set update token
c.requestor.headers.update({"Authorization": "token"})
Parameters starts with '_' or not found in openapi spec, will be passed through to the requesting.
How about c.createPets(json={xx}, _headers={auth config in header}, _params={}, _cookies={or auth config in cookie})?
@SLdragon
Sure, good idea, will have a try, thank you!