mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
[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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user