MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / wrapper

Method wrapper

camel/toolkits/open_api_toolkit.py:256–368  ·  view source on GitHub ↗
(**kwargs)

Source from the content-addressed store, hash-verified

254
255 def inner_decorator(openapi_function: Callable) -> Callable:
256 def wrapper(**kwargs):
257 request_url = f"{base_url.rstrip('/')}/{path.lstrip('/')}"
258 headers = {}
259 params = {}
260 cookies = {}
261
262 # Security definition of operation overrides any declared
263 # top-level security.
264 sec_requirements = operation.get('security', openapi_security)
265 avail_sec_requirement = {}
266 # Write to avaliable_security_requirement only if all the
267 # security_type are "apiKey"
268 for security_requirement in sec_requirements:
269 have_unsupported_type = False
270 for sec_scheme_name, _ in security_requirement.items():
271 sec_type = sec_schemas.get(sec_scheme_name).get('type')
272 if sec_type != "apiKey":
273 have_unsupported_type = True
274 break
275 if have_unsupported_type is False:
276 avail_sec_requirement = security_requirement
277 break
278
279 if sec_requirements and not avail_sec_requirement:
280 raise TypeError(
281 "Only security schemas of type `apiKey` are supported."
282 )
283
284 for sec_scheme_name, _ in avail_sec_requirement.items():
285 try:
286 API_KEY_NAME = openapi_security_config.get(
287 api_name
288 ).get(sec_scheme_name)
289 api_key_value = os.environ[API_KEY_NAME]
290 except Exception:
291 api_key_url = openapi_security_config.get(
292 api_name
293 ).get('get_api_key_url')
294 raise ValueError(
295 f"`{API_KEY_NAME}` not found in environment "
296 f"variables. "
297 f"Get `{API_KEY_NAME}` here: {api_key_url}"
298 )
299 request_key_name = sec_schemas.get(sec_scheme_name).get(
300 'name'
301 )
302 request_key_in = sec_schemas.get(sec_scheme_name).get('in')
303 if request_key_in == 'query':
304 params[request_key_name] = api_key_value
305 elif request_key_in == 'header':
306 headers[request_key_name] = api_key_value
307 elif request_key_in == 'coolie':
308 cookies[request_key_name] = api_key_value
309
310 # Assign parameters to the correct position
311 for param in operation.get('parameters', []):
312 input_param_name = param['name'] + '_in_' + param['in']
313 # Irrelevant arguments does not affect function operation

Callers

nothing calls this directly

Calls 1

jsonMethod · 0.45

Tested by

no test coverage detected