[BugFix] Fix Provider Interface Body Assignment Of Dict-Like Parameters (#6561)

* fix provider interface body assignment for Dict-like parameters.

* 3.9 safe

---------

Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
This commit is contained in:
Danglewood
2024-07-04 03:00:08 -07:00
committed by GitHub
parent 8877f61698
commit 5ba5472553

View File

@@ -15,7 +15,7 @@ from typing import (
Union,
)
from fastapi import Query
from fastapi import Body, Query
from pydantic import (
BaseModel,
ConfigDict,
@@ -290,6 +290,23 @@ class ProviderInterface(metaclass=SingletonMeta):
else:
default = field.default
if (
hasattr(annotation, "__name__")
and annotation.__name__ in ["Dict", "dict", "Data"] # type: ignore
or field.kw_only is True
):
return DataclassField(
new_name,
annotation,
Body(
default=default,
title=provider_name,
description=description,
alias=field.alias or None,
json_schema_extra=getattr(field, "json_schema_extra", None),
),
)
if query:
# We need to use query if we want the field description to show
# up in the swagger, it's a fastapi limitation