from typing import Iterable
from typing import Optional


def _keep_common_path(paths: Iterable[str]) -> str:
    """
    Return common path shared in the object keys' path, formatted as a prefix (with a "/").

    When the list of paths is empty, an empty string is returned.

    >>> _keep_common_path(["production/schemas/dw/fact_order.sql"])
    'production/schemas/dw/fact_order.sql'
    >>> _keep_common_path(
    ...     ["production/schemas/dw/fact_order.sql", "production/schemas/dw/fact_order.yaml"]
    ... )
    'production/schemas/dw/'
    >>> _keep_common_path(
    ...     ["prod/schemas/dw/fact_order.yaml", "prod/schemas/web_app/public-orders.yaml"]
    ... )
    'prod/schemas/'
    >>> _keep_common_path(["dev/schemas/oops/longer_than_path/", "dev/schemas/oops/lo"])
    'dev/schemas/oops/'
    """
    common_path: Optional[str] = None
    for path in paths:
        if common_path is None:
            common_path = path
            continue
        if path.startswith(common_path):
            continue
        for i, c in enumerate(common_path):
            if i == len(path) or path[i] != c:
                common_prefix = common_path[:i]
                slash_index = common_prefix.rfind("/")
                common_path = common_prefix[: slash_index + 1]
                break
    return common_path or ""