mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-21 19:18:41 +00:00
Missing path model fields
This commit is contained in:
parent
90bbc558d0
commit
aa7ed31acd
3 changed files with 54 additions and 6 deletions
|
@ -5,6 +5,7 @@ from openapi_core.compat import lru_cache
|
|||
from openapi_core.schema.operations.generators import OperationsGenerator
|
||||
from openapi_core.schema.parameters.generators import ParametersGenerator
|
||||
from openapi_core.schema.paths.models import Path
|
||||
from openapi_core.schema.servers.generators import ServersGenerator
|
||||
|
||||
|
||||
class PathsGenerator(object):
|
||||
|
@ -15,18 +16,38 @@ class PathsGenerator(object):
|
|||
|
||||
def generate(self, paths):
|
||||
paths_deref = self.dereferencer.dereference(paths)
|
||||
for path_name, path in iteritems(paths_deref):
|
||||
operations = self.operations_generator.generate(path_name, path)
|
||||
for path_name, path_spec in iteritems(paths_deref):
|
||||
path_deref = self.dereferencer.dereference(path_spec)
|
||||
|
||||
parameters_list = path_deref.get('parameters', [])
|
||||
summary = path_deref.get('summary')
|
||||
description = path_deref.get('description')
|
||||
servers_spec = path_deref.get('servers', [])
|
||||
|
||||
operations = self.operations_generator.generate(
|
||||
path_name, path_deref)
|
||||
servers = self.servers_generator.generate(servers_spec)
|
||||
parameters = self.parameters_generator.generate_from_list(
|
||||
path.get('parameters', {})
|
||||
parameters_list)
|
||||
yield (
|
||||
path_name,
|
||||
Path(
|
||||
path_name, list(operations), parameters=list(parameters),
|
||||
summary=summary, description=description,
|
||||
servers=list(servers),
|
||||
),
|
||||
)
|
||||
yield path_name, Path(path_name, list(operations), parameters)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
def operations_generator(self):
|
||||
return OperationsGenerator(self.dereferencer, self.schemas_registry)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
def servers_generator(self):
|
||||
return ServersGenerator(self.dereferencer)
|
||||
|
||||
@property
|
||||
@lru_cache()
|
||||
def parameters_generator(self):
|
||||
|
|
|
@ -4,9 +4,15 @@
|
|||
class Path(object):
|
||||
"""Represents an OpenAPI Path."""
|
||||
|
||||
def __init__(self, name, operations, parameters=None):
|
||||
def __init__(
|
||||
self, name, operations,
|
||||
summary=None, description=None, parameters=None, servers=None,
|
||||
):
|
||||
self.name = name
|
||||
self.operations = dict(operations)
|
||||
self.summary = summary
|
||||
self.description = description
|
||||
self.servers = servers
|
||||
self.parameters = dict(parameters) if parameters else {}
|
||||
|
||||
def __getitem__(self, http_method):
|
||||
|
|
|
@ -93,10 +93,31 @@ class TestPetstore(object):
|
|||
|
||||
for path_name, path in iteritems(spec.paths):
|
||||
assert type(path) == Path
|
||||
|
||||
path_spec = spec_dict['paths'][path_name]
|
||||
assert path.name == path_name
|
||||
assert path.summary == path_spec.get('summary')
|
||||
assert path.description == path_spec.get('description')
|
||||
|
||||
servers_spec = path_spec.get('servers', [])
|
||||
for idx, server in enumerate(path.servers):
|
||||
assert type(server) == Server
|
||||
|
||||
server_spec = servers_spec[idx]
|
||||
assert server.url == server_spec['url']
|
||||
assert server.default_url == server_spec['url']
|
||||
assert server.description == server_spec.get('description')
|
||||
|
||||
for variable_name, variable in iteritems(server.variables):
|
||||
assert type(variable) == ServerVariable
|
||||
assert variable.name == variable_name
|
||||
|
||||
variable_spec = server_spec['variables'][variable_name]
|
||||
assert variable.default == variable_spec['default']
|
||||
assert variable.enum == variable_spec.get('enum')
|
||||
|
||||
for http_method, operation in iteritems(path.operations):
|
||||
operation_spec = spec_dict['paths'][path_name][http_method]
|
||||
operation_spec = path_spec[http_method]
|
||||
|
||||
assert type(operation) == Operation
|
||||
assert operation.path_name == path_name
|
||||
|
|
Loading…
Reference in a new issue