-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathregistries.py
More file actions
19 lines (15 loc) · 650 Bytes
/
registries.py
File metadata and controls
19 lines (15 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from collections import defaultdict
from collections.abc import Mapping
from openapi_spec_validator.validation.keywords import KeywordValidator
class KeywordValidatorRegistry(defaultdict[str, KeywordValidator]):
def __init__(
self, keyword_validators: Mapping[str, type[KeywordValidator]]
):
super().__init__()
self.keyword_validators = keyword_validators
def __missing__(self, keyword: str) -> KeywordValidator:
if keyword not in self.keyword_validators:
raise KeyError(keyword)
cls = self.keyword_validators[keyword]
self[keyword] = cls(self)
return self[keyword]