Check if field type is a Union where all members are BaseModel subclasses.
(field_type: Any)
| 871 | |
| 872 | |
| 873 | def is_union_of_base_models(field_type: Any) -> bool: |
| 874 | """Check if field type is a Union where all members are BaseModel subclasses.""" |
| 875 | from fastapi.types import UnionType |
| 876 | |
| 877 | origin = get_origin(field_type) |
| 878 | |
| 879 | # Check if it's a Union type (covers both typing.Union and types.UnionType in Python 3.10+) |
| 880 | if origin is not Union and origin is not UnionType: |
| 881 | return False |
| 882 | |
| 883 | union_args = get_args(field_type) |
| 884 | |
| 885 | for arg in union_args: |
| 886 | if not lenient_issubclass(arg, BaseModel): |
| 887 | return False |
| 888 | |
| 889 | return True |
| 890 | |
| 891 | |
| 892 | def _should_embed_body_fields(fields: list[ModelField]) -> bool: |
no test coverage detected