Home / Function/ is_union_of_base_models() — fastapi Function Reference

is_union_of_base_models() — fastapi Function Reference

Architecture documentation for the is_union_of_base_models() function in utils.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  0d837460_f27d_53af_8d59_7190a2a974f5["is_union_of_base_models()"]
  9e602cbf_3139_86ae_5666_97b8806942de["utils.py"]
  0d837460_f27d_53af_8d59_7190a2a974f5 -->|defined in| 9e602cbf_3139_86ae_5666_97b8806942de
  18580490_8a5f_0766_c8e1_329e703c7527["_should_embed_body_fields()"]
  18580490_8a5f_0766_c8e1_329e703c7527 -->|calls| 0d837460_f27d_53af_8d59_7190a2a974f5
  style 0d837460_f27d_53af_8d59_7190a2a974f5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fastapi/dependencies/utils.py lines 839–855

def is_union_of_base_models(field_type: Any) -> bool:
    """Check if field type is a Union where all members are BaseModel subclasses."""
    from fastapi.types import UnionType

    origin = get_origin(field_type)

    # Check if it's a Union type (covers both typing.Union and types.UnionType in Python 3.10+)
    if origin is not Union and origin is not UnionType:
        return False

    union_args = get_args(field_type)

    for arg in union_args:
        if not lenient_issubclass(arg, BaseModel):
            return False

    return True

Subdomains

Frequently Asked Questions

What does is_union_of_base_models() do?
is_union_of_base_models() is a function in the fastapi codebase, defined in fastapi/dependencies/utils.py.
Where is is_union_of_base_models() defined?
is_union_of_base_models() is defined in fastapi/dependencies/utils.py at line 839.
What calls is_union_of_base_models()?
is_union_of_base_models() is called by 1 function(s): _should_embed_body_fields.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free