mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
23 lines
622 B
Python
23 lines
622 B
Python
from contextlib import contextmanager
|
|
|
|
from dictpath.accessors import DictOrListAccessor
|
|
|
|
|
|
class SpecAccessor(DictOrListAccessor):
|
|
|
|
def __init__(self, dict_or_list, dereferencer):
|
|
super(SpecAccessor, self).__init__(dict_or_list)
|
|
self.dereferencer = dereferencer
|
|
|
|
@contextmanager
|
|
def open(self, parts):
|
|
content = self.dict_or_list
|
|
for part in parts:
|
|
content = content[part]
|
|
if '$ref' in content:
|
|
content = self.dereferencer.dereference(
|
|
content)
|
|
try:
|
|
yield content
|
|
finally:
|
|
pass
|