|
4 | 4 | import json
|
5 | 5 | import os.path as opath
|
6 | 6 |
|
| 7 | +DERIVED_CLASSES = { |
| 8 | + "DataValidator": "data", |
| 9 | + "LayoutValidator": "layout", |
| 10 | +} |
| 11 | + |
7 | 12 | class ValidatorCache(object):
|
8 | 13 | _cache = {}
|
9 | 14 | _json_cache = None
|
@@ -43,8 +48,23 @@ def get_validator(parent_path, prop_name):
|
43 | 48 | lookup_name = lookup_name or prop_name
|
44 | 49 | lookup = f"{parent_path}.{lookup_name}" if parent_path else lookup_name
|
45 | 50 | validator_item = ValidatorCache._json_cache.get(lookup)
|
| 51 | + validator_classname = validator_item["superclass"] |
| 52 | + if validator_classname in DERIVED_CLASSES: |
| 53 | + # If the superclass is a derived class, we need to get the base class |
| 54 | + # and pass the derived class name as a parameter |
| 55 | + base_item = ValidatorCache._json_cache.get( |
| 56 | + DERIVED_CLASSES[validator_classname] |
| 57 | + ) |
| 58 | + validator_args = base_item["params"] |
| 59 | + validator_args.update(validator_item["params"]) |
| 60 | + validator_classname = base_item["superclass"] |
| 61 | + else: |
| 62 | + validator_args = validator_item["params"] |
| 63 | + |
| 64 | + validator_class = getattr(basevalidators, validator_classname) |
| 65 | + |
46 | 66 | print("validator_item", key, validator_item)
|
47 |
| - validator = generate_validator(validator_item["params"], validator_item["superclass"]) |
| 67 | + validator = validator_class(**validator_args) |
48 | 68 | ValidatorCache._cache[key] = validator
|
49 | 69 |
|
50 | 70 | return ValidatorCache._cache[key]
|
|
0 commit comments