def _validate()

in src/validators/utils.py [0:0]


def _validate(kwargs: dict[str, Any], types: dict[str, type],
              cast: bool = True) -> dict[str, Any]:
    """
    Received keys and values in `kwargs`, keys and expected values' types
    in `types`. Returns a dict with keys and validated values
    :param kwargs:
    :param types:
    :param cast:
    :return:
    """
    validated = {}
    for key, value in kwargs.items():
        if key not in types:
            validated[key] = value
            continue
        _type = types[key]
        if issubclass(_type, BaseModel):
            valid = validate_pydantic(_type, value)
            if not cast:
                valid = valid.dict()
            validated[key] = valid
        else:
            # supposedly here will be only dynamic url params. Their
            # rightness depends not on the user but on the developer. Value
            # shall be always cast-able
            valid = validate_type(_type, value)
            if not cast:
                valid = value
            validated[key] = valid
    return validated