mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
[Feature] openbb-platform-api: Adds Configurations Supplied In Router Decorator To widgets.json (#7014)
* add reading a 'widget_config' dictionary from openapi_extra that can be supplied in the router decorator * fix response_ref * fix some more key errors when no_validate is True and response_model is not None, although response model is always OBBject despite what FastAPI says.. * elif * test fix
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user