def _validate_dict()

in source/aws_lambda/shared/personalize_service.py [0:0]


    def _validate_dict(self, config: Dict, schema: List, path=""):
        allowed = [
            k
            if isinstance(k, str)
            else next(iter(k.keys()))
            if isinstance(k, dict)
            else k[0]
            for k in schema
        ]
        sub_validations = [i for i in schema if isinstance(i, dict)]

        for key, value in config.items():
            current_path = [path, key]
            current_path = ".".join([i for i in current_path if i])
            if key not in allowed:
                self._configuration_errors.append(
                    f"key {current_path} is not an allowed key"
                )

            try:
                sub_validation = [v for v in sub_validations if v.get(key)].pop()
                self._validate_keys(value, sub_validation[key], current_path)
            except IndexError:
                pass  # no sub validations