fix: serialize response before fastapi (#6279)

This commit is contained in:
montezdesousa
2024-04-02 18:41:48 +01:00
committed by GitHub
parent bc77e071b7
commit 83d03bc254
2 changed files with 7 additions and 9 deletions

View File

@@ -117,7 +117,7 @@ def build_new_signature(path: str, func: Callable) -> Signature:
)
def validate_output(c_out: OBBject) -> OBBject:
def validate_output(c_out: OBBject) -> Dict:
"""
Validate OBBject object.
@@ -132,8 +132,8 @@ def validate_output(c_out: OBBject) -> OBBject:
Returns
-------
OBBject
Validated OBBject object.
Dict
Serialized OBBject.
"""
def is_model(type_):
@@ -170,7 +170,7 @@ def validate_output(c_out: OBBject) -> OBBject:
for k, v in c_out.model_copy():
exclude_fields_from_api(k, v)
return c_out
return c_out.model_dump()
def build_api_wrapper(
@@ -188,7 +188,7 @@ def build_api_wrapper(
func.__annotations__ = new_annotations_map
@wraps(wrapped=func)
async def wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]):
async def wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]) -> Dict:
user_settings: UserSettings = UserSettings.model_validate(
kwargs.pop(
"__authenticated_user_settings",
@@ -198,8 +198,7 @@ def build_api_wrapper(
execute = partial(command_runner.run, path, user_settings)
output: OBBject = await execute(*args, **kwargs)
output = validate_output(output)
return output
return validate_output(output)
return wrapper

View File

@@ -110,7 +110,7 @@ class RegistryMap:
fetcher: Fetcher,
model_map: dict,
):
"""Merge json schema extra for different providers"""
"""Merge json schema extra for different providers."""
model: BaseModel = RegistryMap._get_model(fetcher, "query_params")
std_fields = model_map["openbb"]["QueryParams"]["fields"]
extra_fields = model_map[provider]["QueryParams"]["fields"]
@@ -157,7 +157,6 @@ class RegistryMap:
Field(
default=provider_str,
description="The data provider for the data.",
exclude=True,
),
)