From 1c26d24e95252797d35fd71bb0df99dccdacf79d Mon Sep 17 00:00:00 2001 From: Henrique Joaquim Date: Wed, 10 Apr 2024 14:50:09 +0100 Subject: [PATCH] [BugFix] `json_schema_extra` getting overridden (#6300) * fix json_schema_extra getting overriden * keeping it as it was --------- Co-authored-by: hjoaquim Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> --- .../openbb_core/app/provider_interface.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/openbb_platform/core/openbb_core/app/provider_interface.py b/openbb_platform/core/openbb_core/app/provider_interface.py index ac43a50a16a..5bef4ac6e6c 100644 --- a/openbb_platform/core/openbb_core/app/provider_interface.py +++ b/openbb_platform/core/openbb_core/app/provider_interface.py @@ -164,9 +164,11 @@ class ProviderInterface(metaclass=SingletonMeta): curr_name = current.name curr_type: Optional[Type] = current.annotation curr_desc = getattr(current.default, "description", "") + curr_json_schema_extra = getattr(current.default, "json_schema_extra", {}) inc_type: Optional[Type] = incoming.annotation inc_desc = getattr(incoming.default, "description", "") + inc_json_schema_extra = getattr(incoming.default, "json_schema_extra", {}) def split_desc(desc: str) -> str: """Split field description.""" @@ -174,6 +176,24 @@ class ProviderInterface(metaclass=SingletonMeta): detail = item[0] if item else "" return detail + def merge_json_schema_extra(curr: dict, inc: dict) -> dict: + """Merge json schema extra.""" + for key in curr.keys() & inc.keys(): + # Merge keys that are in both dictionaries if both are lists + curr_value = curr[key] + inc_value = inc[key] + if isinstance(curr_value, list) and isinstance(inc_value, list): + curr[key] = list(set(curr.get(key, []) + inc.get(key, []))) + inc.pop(key) + + # Add any remaining keys from inc to curr + curr.update(inc) + return curr + + json_schema_extra: dict = merge_json_schema_extra( + curr=curr_json_schema_extra or {}, inc=inc_json_schema_extra or {} + ) + curr_detail = split_desc(curr_desc) inc_detail = split_desc(inc_desc) @@ -192,6 +212,7 @@ class ProviderInterface(metaclass=SingletonMeta): default=getattr(current.default, "default", None), title=providers, description=new_desc, + json_schema_extra=json_schema_extra, ) merged_type: Optional[Type] = (