-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathregistries.py
32 lines (21 loc) · 937 Bytes
/
registries.py
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
29
30
31
32
"""OpenAPI core schemas registries module"""
import logging
from lazy_object_proxy import Proxy
from openapi_core.schema.schemas.factories import SchemaFactory
from openapi_core.schema.schemas.util import dicthash
log = logging.getLogger(__name__)
class SchemaRegistry(SchemaFactory):
def __init__(self, dereferencer):
super(SchemaRegistry, self).__init__(dereferencer)
self._schemas = {}
def get_or_create(self, schema_spec, schema_name=''):
schema_hash = dicthash(schema_spec)
schema_deref = self.dereferencer.dereference(schema_spec)
if schema_hash in self._schemas:
return self._schemas[schema_hash], False
if '$ref' in schema_spec:
schema = Proxy(lambda: self.create(schema_deref, schema_name))
else:
schema = self.create(schema_deref, schema_name)
self._schemas[schema_hash] = schema
return schema, True