Repository: tiangolo/fastapi
File: fastapi/dependencies/utils.py (Python)

Code before:
    if any(isinstance(f.field_info, params.File) for f in flat_dependant.body_params):
        BodyFieldInfo: Type[params.Body] = params.File
    elif any(isinstance(f.field_info, params.Form) for f in flat_dependant.body_params):
        BodyFieldInfo = params.Form
    else:
        BodyFieldInfo = params.Body

        body_param_media_types = [
            f.field_info.media_type
            for f in flat_dependant.body_params
            if isinstance(f.field_info, params.Body)
        ]
        if len(set(body_param_media_types)) == 1:
            BodyFieldInfo_kwargs["media_type"] = body_param_media_types[0]
    final_field = create_model_field(
        name="body",
        type_=BodyModel,
        required=required,
        alias="body",
        field_info=BodyFieldInfo(**BodyFieldInfo_kwargs),
    )
    return final_field


def _is_typealiastype(tp: Any, /) -> TypeGuard[TypeAliasType]:
    in_typing = hasattr(typing, "TypeAliasType")
    in_typing_extensions = hasattr(typing_extensions, "TypeAliasType")
    is_typealiastype = False
    if in_typing and in_typing_extensions:
        if getattr(typing, "TypeAliasType", None) is getattr(
            typing_extensions, "TypeAliasType", None
        ):  # pragma: no cover
            is_typealiastype = isinstance(tp, typing.TypeAliasType)  # type: ignore [attr-defined]
        else:
            is_typealiastype = isinstance(
                tp,
                (typing.TypeAliasType, typing_extensions.TypeAliasType),  # type: ignore [attr-defined]
            )
    elif in_typing and not in_typing_extensions:  # pragma: no cover
        is_typealiastype = isinstance(tp, typing.TypeAliasType)  # type: ignore [attr-defined]
    elif not in_typing and in_typing_extensions:
        is_typealiastype = isinstance(tp, typing_extensions.TypeAliasType)
    if sys.version_info[:2] == (3, 10):
        return type(tp) is not GenericAlias and is_typealiastype
    return is_typealiastype


Review comment (suggestion):
```suggestion
    """
    This implementation is in line with the implementation of `is_typealiastype` in `typing-inspection`:
    See:
    - https://github.com/pydantic/typing-inspection/blob/8db011350942f33ac4b5d7db60d4d9ea83ab480f/src/typing_inspection/typing_objects.py#L488-L499
    - https://github.com/pydantic/typing-inspection/blob/8db011350942f33ac4b5d7db60d4d9ea83ab480f/src/typing_inspection/typing_objects.py#L105-L134
    """

    # Check if TypeAliasType exists in typing and/or typing_extensions.
    in_typing = hasattr(typing, "TypeAliasType")
```

Code after:
        "alias": "body",
    }
    if not required:
        BodyFieldInfo_kwargs["default"] = None
    if any(isinstance(f.field_info, params.File) for f in flat_dependant.body_params):
        BodyFieldInfo: type[params.Body] = params.File
    elif any(isinstance(f.field_info, params.Form) for f in flat_dependant.body_params):
        BodyFieldInfo = params.Form
    else:
        BodyFieldInfo = params.Body

        body_param_media_types = [
            f.field_info.media_type
            for f in flat_dependant.body_params
            if isinstance(f.field_info, params.Body)
        ]
        if len(set(body_param_media_types)) == 1:
            BodyFieldInfo_kwargs["media_type"] = body_param_media_types[0]
    final_field = create_model_field(
        name="body",
        type_=BodyModel,
        required=required,
        alias="body",
        field_info=BodyFieldInfo(**BodyFieldInfo_kwargs),
    )
    return final_field


def get_validation_alias(field: ModelField) -> str:
    va = getattr(field, "validation_alias", None)
    return va or field.alias