openapi-core/openapi_core/schema/schemas/registries.py
2018-05-25 11:30:50 +01:00

22 lines
624 B
Python

"""OpenAPI core schemas registries module"""
import logging
from openapi_core.schema.schemas.factories import SchemaFactory
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_deref = self.dereferencer.dereference(schema_spec)
model = schema_deref.get('x-model', None)
if model and model in self._schemas:
return self._schemas[model], False
return self.create(schema_deref), True