44import json
55import os
66import typing as t
7+ import warnings
78from collections import defaultdict
89from dataclasses import dataclass
910from io import BufferedReader
@@ -147,12 +148,14 @@ class OpenAPI:
147148 auth_provider: Object that returns requests auth objects according to the api spec.
148149 cert: Client certificate used for auth.
149150 key: Matching key for `cert` if not already included.
150- verify : Whether to check server TLS certificates agains a CA (requests semantic).
151+ verify_ssl : Whether to check server TLS certificates agains a CA (requests semantic).
151152 refresh_cache: Whether to fetch the api doc regardless.
152- safe_calls_only : Flag to disallow issuing POST, PUT, PATCH or DELETE calls.
153+ dry_run : Flag to disallow issuing POST, PUT, PATCH or DELETE calls.
153154 debug_callback: Callback that will be called with strings useful for logging or debugging.
154155 user_agent: String to use in the User-Agent header.
155156 cid: Correlation ID to send with all requests.
157+ validate_certs: DEPRECATED use verify_ssl instead.
158+ safe_calls_only: DEPRECATED use dry_run instead.
156159 """
157160
158161 def __init__ (
@@ -163,19 +166,28 @@ def __init__(
163166 auth_provider : t .Optional [AuthProviderBase ] = None ,
164167 cert : t .Optional [str ] = None ,
165168 key : t .Optional [str ] = None ,
166- verify : t .Optional [t .Union [bool , str ]] = True ,
169+ verify_ssl : t .Optional [t .Union [bool , str ]] = True ,
167170 refresh_cache : bool = False ,
168- safe_calls_only : bool = False ,
171+ dry_run : bool = False ,
169172 debug_callback : t .Optional [t .Callable [[int , str ], t .Any ]] = None ,
170173 user_agent : t .Optional [str ] = None ,
171174 cid : t .Optional [str ] = None ,
175+ validate_certs : t .Optional [bool ] = None ,
176+ safe_calls_only : t .Optional [bool ] = None ,
172177 ):
178+ if validate_certs is not None :
179+ warnings .warn ("validate_certs is deprecated; use verify_ssl instead." )
180+ verify_ssl = validate_certs
181+ if safe_calls_only is not None :
182+ warnings .warn ("safe_calls_only is deprecated; use dry_run instead." )
183+ dry_run = safe_calls_only
184+
173185 self ._debug_callback : t .Callable [[int , str ], t .Any ] = debug_callback or (lambda i , x : None )
174186 self ._base_url : str = base_url
175187 self ._doc_path : str = doc_path
176- self ._safe_calls_only : bool = safe_calls_only
188+ self ._dry_run : bool = dry_run
177189 self ._headers = CIMultiDict (headers or {})
178- self ._verify = verify
190+ self ._verify_ssl = verify_ssl
179191 self ._auth_provider = auth_provider
180192 self ._cert = cert
181193 self ._key = key
@@ -196,7 +208,7 @@ def __init__(
196208 def _setup_session (self ) -> None :
197209 # This is specific requests library.
198210
199- if self ._verify is False :
211+ if self ._verify_ssl is False :
200212 urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
201213
202214 self ._session : requests .Session = requests .session ()
@@ -214,7 +226,7 @@ def _setup_session(self) -> None:
214226 elif self ._key :
215227 raise OpenAPIError (_ ("Cert is required if key is set." ))
216228 session_settings = self ._session .merge_environment_settings (
217- self ._base_url , {}, None , self ._verify , None
229+ self ._base_url , {}, None , self ._verify_ssl , None
218230 )
219231 self ._session .verify = session_settings ["verify" ]
220232 self ._session .proxies = session_settings ["proxies" ]
@@ -511,7 +523,7 @@ def _send_request(
511523 self ._debug_callback (2 , f" { key } : { value } " )
512524 if request .body is not None :
513525 self ._debug_callback (3 , f"{ request .body !r} " )
514- if self ._safe_calls_only and method .upper () not in SAFE_METHODS :
526+ if self ._dry_run and method .upper () not in SAFE_METHODS :
515527 raise UnsafeCallError (_ ("Call aborted due to safe mode" ))
516528 try :
517529 response = self ._session .send (request )
0 commit comments