MCPcopy Create free account
hub / github.com/fastapi/fastapi / is_union_of_base_models

Function is_union_of_base_models

fastapi/dependencies/utils.py:873–889  ·  view source on GitHub ↗

Check if field type is a Union where all members are BaseModel subclasses.

(field_type: Any)

Source from the content-addressed store, hash-verified

871
872
873def 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
892def _should_embed_body_fields(fields: list[ModelField]) -> bool:

Callers 1

Calls 1

lenient_issubclassFunction · 0.90

Tested by

no test coverage detected