from typing import MutableMapping
from typing import Any
from typing import OrderedDict


def sort_nested_dict(mmap: MutableMapping[str, Any]) -> OrderedDict:
    """Sorted nested dictionary by key.

    Args:
        dict_: Mapping to mutate by sorting.

    Returns:
        Sorted map.
    """

    for key, val in mmap.items():
        if isinstance(val, dict):
            mmap[key] = sort_nested_dict(val)

    return OrderedDict(sorted(mmap.items()))