diff options
author | Henrique Joaquim <henriquecjoaquim@gmail.com> | 2024-04-10 14:50:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 13:50:09 +0000 |
commit | 1c26d24e95252797d35fd71bb0df99dccdacf79d (patch) | |
tree | 98733825b95ad505ae202591c3fb070312350b8b | |
parent | 951749156dae3029c43364887c332036589aad7e (diff) |
[BugFix] `json_schema_extra` getting overridden (#6300)
* fix json_schema_extra getting overriden
* keeping it as it was
---------
Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
-rw-r--r-- | openbb_platform/core/openbb_core/app/provider_interface.py | 21 |
1 files changed, 21 insertions, 0 deletions
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] = ( |