diff --git a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py index 3212d921491..4dff9cff40d 100644 --- a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py +++ b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/openapi.py @@ -354,17 +354,26 @@ def get_data_schema_for_widget(openapi_json, operation_id): ][ "application/json" ].get( - "schema", "" - ) - # Extract the schema name from the reference - schema_name = response_ref.split("/")[-1] - # Fetch and return the schema from components - return ( - openapi_json["components"]["schemas"][schema_name] - .get("properties", {}) - .get("results", {}) + "schema" ) + if isinstance(response_ref, dict) and "type" in response_ref: + response_ref = response_ref["type"] + + if response_ref: + # Extract the schema name from the reference + schema_name = response_ref.split("/")[-1] + # Fetch and return the schema from components + if ( + schema_name + and schema_name in openapi_json["components"]["schemas"] + ): + return ( + openapi_json["components"]["schemas"][schema_name] + .get("properties", {}) + .get("results", {}) + ) + # Return None if the schema is not found return None @@ -377,7 +386,7 @@ def data_schema_to_columns_defs(openapi_json, operation_id, provider): result_schema_ref = get_data_schema_for_widget(openapi_json, operation_id) # Check if 'anyOf' is in the result_schema_ref and handle the nested structure - if "anyOf" in result_schema_ref: + if result_schema_ref and "anyOf" in result_schema_ref: for item in result_schema_ref["anyOf"]: # When there are multiple providers a 'oneOf' is used if "items" in item and "oneOf" in item["items"]: @@ -397,7 +406,7 @@ def data_schema_to_columns_defs(openapi_json, operation_id, provider): schemas = [ openapi_json["components"]["schemas"][ref] for ref in schema_refs - if ref in openapi_json["components"]["schemas"] + if ref and ref in openapi_json["components"]["schemas"] ] # Proceed with finding common keys and generating column definitions diff --git a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py index 7c4254d5de2..6ba65b60177 100644 --- a/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py +++ b/openbb_platform/extensions/platform_api/openbb_platform_api/utils/widgets.py @@ -82,7 +82,7 @@ def build_json(openapi: dict, widget_exclude_filter: list): route_api = openapi["paths"][route] method = list(route_api)[0] widget_id = route_api[method]["operationId"] - + widget_config_dict = route_api[method].get("widget_config", {}) # 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"][ @@ -178,6 +178,10 @@ def build_json(openapi: dict, widget_exclude_filter: list): if columns_defs: widget_config["data"]["table"]["columnsDefs"] = columns_defs + # Update the widget configuration with the supplied configurations in @router.command + if widget_config_dict: + widget_config.update(widget_config_dict) + # Add the widget configuration to the widgets.json if widget_config["widgetId"] not in widget_exclude_filter: widgets_json[widget_config["widgetId"]] = widget_config