File size: 908 Bytes
8983b2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# slotmatch/schema.py

ALLOWED_TYPES = {str, int, float, bool}

class SchemaValidationError(Exception):
    """Custom error when schema is invalid."""
    pass

class SchemaValidator:
    def __init__(self, schema: dict):
        self.schema = schema
        self._validate_schema()

    def _validate_schema(self):
        if not isinstance(self.schema, dict):
            raise SchemaValidationError("Schema must be a dictionary.")

        for key, expected_type in self.schema.items():
            if not isinstance(key, str):
                raise SchemaValidationError(f"Key '{key}' must be a string.")
            if expected_type not in ALLOWED_TYPES:
                raise SchemaValidationError(
                    f"Unsupported type '{expected_type}' for key '{key}'. "
                    f"Supported types: {ALLOWED_TYPES}"
                )

    def get_schema(self):
        return self.schema