Move path finder to separate templating module

This commit is contained in:
Artur Maciag 2020-02-21 16:25:10 +00:00
parent 8539d9b0f4
commit 817ff5c746
8 changed files with 32 additions and 22 deletions

View file

View file

@ -0,0 +1,27 @@
"""OpenAPI core templating paths finders module"""
from openapi_core.templating.paths.util import get_operation_pattern
class PathFinder(object):
def __init__(self, spec):
self.spec = spec
def find(self, request):
operation_pattern = self._get_operation_pattern(request)
path = self.spec[operation_pattern]
path_variables = {}
operation = self.spec.get_operation(operation_pattern, request.method)
servers = path.servers or operation.servers or self.spec.servers
server = servers[0]
server_variables = {}
return path, operation, server, path_variables, server_variables
def _get_operation_pattern(self, request):
server = self.spec.get_server(request.full_url_pattern)
return get_operation_pattern(
server.default_url, request.full_url_pattern
)

View file

@ -1,4 +1,4 @@
"""OpenAPI core validation util module"""
"""OpenAPI core templating paths util module"""
from six.moves.urllib.parse import urlparse

View file

@ -21,7 +21,6 @@ from openapi_core.validation.exceptions import InvalidSecurity
from openapi_core.validation.request.datatypes import (
RequestParameters, RequestValidationResult,
)
from openapi_core.validation.util import get_operation_pattern
from openapi_core.validation.validators import BaseValidator

View file

@ -13,7 +13,6 @@ from openapi_core.unmarshalling.schemas.exceptions import (
UnmarshalError, ValidateError,
)
from openapi_core.validation.response.datatypes import ResponseValidationResult
from openapi_core.validation.util import get_operation_pattern
from openapi_core.validation.validators import BaseValidator

View file

@ -1,5 +1,4 @@
"""OpenAPI core validation validators module"""
from openapi_core.validation.util import get_operation_pattern
class BaseValidator(object):
@ -13,23 +12,9 @@ class BaseValidator(object):
self.custom_media_type_deserializers = custom_media_type_deserializers
def _find_path(self, request):
operation_pattern = self._get_operation_pattern(request)
path = self.spec[operation_pattern]
path_variables = {}
operation = self.spec.get_operation(operation_pattern, request.method)
servers = path.servers or operation.servers or self.spec.servers
server = servers[0]
server_variables = {}
return path, operation, server, path_variables, server_variables
def _get_operation_pattern(self, request):
server = self.spec.get_server(request.full_url_pattern)
return get_operation_pattern(
server.default_url, request.full_url_pattern
)
from openapi_core.templating.paths.finders import PathFinder
finder = PathFinder(self.spec)
return finder.find(request)
def _deserialise_media_type(self, media_type, value):
from openapi_core.deserializing.media_types.factories import (

View file

@ -1,4 +1,4 @@
from openapi_core.validation.util import path_qs
from openapi_core.templating.paths.util import path_qs
class TestPathQs(object):