2017-09-21 11:51:37 +00:00
|
|
|
"""OpenAPI core paths module"""
|
2017-09-22 08:54:37 +00:00
|
|
|
from functools import lru_cache
|
|
|
|
|
2017-09-21 11:51:37 +00:00
|
|
|
from six import iteritems
|
|
|
|
|
|
|
|
from openapi_core.operations import OperationsGenerator
|
|
|
|
|
|
|
|
|
|
|
|
class Path(object):
|
|
|
|
"""Represents an OpenAPI Path."""
|
|
|
|
|
|
|
|
def __init__(self, name, operations):
|
|
|
|
self.name = name
|
|
|
|
self.operations = dict(operations)
|
|
|
|
|
|
|
|
def __getitem__(self, http_method):
|
|
|
|
return self.operations[http_method]
|
|
|
|
|
|
|
|
|
|
|
|
class PathsGenerator(object):
|
|
|
|
|
2017-09-22 08:54:37 +00:00
|
|
|
def __init__(self, dereferencer, schemas_registry):
|
2017-09-21 11:51:37 +00:00
|
|
|
self.dereferencer = dereferencer
|
2017-09-22 08:54:37 +00:00
|
|
|
self.schemas_registry = schemas_registry
|
2017-09-21 11:51:37 +00:00
|
|
|
|
|
|
|
def generate(self, paths):
|
|
|
|
paths_deref = self.dereferencer.dereference(paths)
|
|
|
|
for path_name, path in iteritems(paths_deref):
|
2017-09-22 08:54:37 +00:00
|
|
|
operations = self.operations_generator.generate(path_name, path)
|
2017-09-21 11:51:37 +00:00
|
|
|
yield path_name, Path(path_name, list(operations))
|
|
|
|
|
2017-09-22 08:54:37 +00:00
|
|
|
@property
|
|
|
|
@lru_cache()
|
|
|
|
def operations_generator(self):
|
|
|
|
return OperationsGenerator(self.dereferencer, self.schemas_registry)
|