mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-29 03:00:12 +00:00
27 lines
707 B
Python
27 lines
707 B
Python
"""OpenAPI core models module"""
|
|
|
|
|
|
class BaseModel(dict):
|
|
"""Base class for OpenAPI models."""
|
|
|
|
def __getattr__(self, attr_name):
|
|
"""Only search through properties if attribute not found normally.
|
|
:type attr_name: str
|
|
"""
|
|
try:
|
|
return self[attr_name]
|
|
except KeyError:
|
|
raise AttributeError(
|
|
'type object {0!r} has no attribute {1!r}'
|
|
.format(type(self).__name__, attr_name)
|
|
)
|
|
|
|
|
|
class ModelFactory(object):
|
|
|
|
def create(self, properties, name=None):
|
|
model = BaseModel
|
|
if name is not None:
|
|
model = type(name, (BaseModel, ), {})
|
|
|
|
return model(**properties)
|