[BugFix] openbb-platform-api: Fix Unsafe Property Access In get_data_schema_for_widget (#7013)

* fix unsafely accessing the  property in get_data_schema_for_widget

* make dataKey the root when no_validate=True

* missed in commit
This commit is contained in:
Danglewood
2025-01-30 11:32:48 -08:00
committed by GitHub
parent c9ea90e786
commit 39a7e3e02e
2 changed files with 14 additions and 3 deletions

View File

@@ -349,7 +349,13 @@ def get_data_schema_for_widget(openapi_json, operation_id):
# Get the reference to the schema from the successful response
response_ref = details["responses"]["200"]["content"][
"application/json"
]["schema"]["$ref"]
].get("schema", {}).get("$ref") or details["responses"]["200"][
"content"
][
"application/json"
].get(
"schema", ""
)
# Extract the schema name from the reference
schema_name = response_ref.split("/")[-1]
# Fetch and return the schema from components

View File

@@ -85,6 +85,9 @@ def build_json(openapi: dict, widget_exclude_filter: list):
# Prepare the query schema of the widget
query_schema, has_chart = get_query_schema_for_widget(openapi, route)
response_schema = route_api[method]["responses"]["200"]["content"][
"application/json"
].get("schema", {})
# Extract providers from the query schema
providers: list = []
@@ -150,7 +153,7 @@ def build_json(openapi: dict, widget_exclude_filter: list):
"endpoint": route.replace("/api", "api"),
"gridData": {"w": 45, "h": 15},
"data": {
"dataKey": "results",
"dataKey": "results" if response_schema else "",
"table": {
"showAll": True,
},
@@ -200,7 +203,9 @@ def build_json(openapi: dict, widget_exclude_filter: list):
widget_config_chart["gridData"]["h"] = 20
widget_config_chart["gridData"]["w"] = 50
widget_config_chart["defaultViz"] = "chart"
widget_config_chart["data"]["dataKey"] = "chart.content"
widget_config_chart["data"]["dataKey"] = (
"chart.content" if response_schema else ""
)
if widget_config_chart["widgetId"] not in widget_exclude_filter:
widgets_json[widget_config_chart["widgetId"]] = widget_config_chart