changes
This commit is contained in:
Binary file not shown.
@@ -86,6 +86,25 @@ def handle_map_expression(expression, context):
|
||||
# ============================
|
||||
# CRUD thông qua API có sẵn
|
||||
# ============================
|
||||
def deep_resolve_values(data, context):
|
||||
if isinstance(data, dict):
|
||||
return {k: deep_resolve_values(v, context) for k, v in data.items()}
|
||||
elif isinstance(data, list):
|
||||
return [deep_resolve_values(item, context) for item in data]
|
||||
elif isinstance(data, str):
|
||||
# Workaround for resolver bug: handle strings that are only a placeholder
|
||||
match = re.fullmatch(r"\{([^}]+)\}", data)
|
||||
if match:
|
||||
# The path is the content inside the braces, e.g., "transaction_detail.id"
|
||||
path = match.group(1)
|
||||
# resolve_value works on raw paths, so call it directly
|
||||
return resolve_value(path, context)
|
||||
else:
|
||||
# This handles complex strings like "/prefix/{path}/" or normal strings
|
||||
return resolve_value(data, context)
|
||||
else:
|
||||
return data
|
||||
|
||||
@register_action("API_CALL", schema={"required": ["method", "url"]})
|
||||
def api_call_action(params, context):
|
||||
"""Thực hiện gọi API nội bộ bằng Django Test Client"""
|
||||
@@ -99,7 +118,7 @@ def api_call_action(params, context):
|
||||
if isinstance(raw_body, str) and raw_body.startswith("$map"):
|
||||
body = handle_map_expression(raw_body, context)
|
||||
elif isinstance(raw_body, dict):
|
||||
body = {k: resolve_value(v, context) for k, v in raw_body.items()}
|
||||
body = deep_resolve_values(raw_body, context)
|
||||
else:
|
||||
body = resolve_value(raw_body, context)
|
||||
|
||||
@@ -115,10 +134,15 @@ def api_call_action(params, context):
|
||||
else:
|
||||
resp = client.get(url)
|
||||
|
||||
print(f" [API_CALL] Status Code: {resp.status_code}")
|
||||
|
||||
if resp.status_code >= 400:
|
||||
raise Exception(f"API Call failed: {resp.content.decode('utf-8')}")
|
||||
error_content = resp.content.decode('utf-8')
|
||||
print(f" [API_CALL] Error: {error_content}")
|
||||
raise Exception(f"API Call failed: {error_content}")
|
||||
|
||||
result = resp.json()
|
||||
print(f" [API_CALL] Result: {result}")
|
||||
if save_as:
|
||||
context[save_as] = result
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user