mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-28 03:00:11 +00:00
Move path finder to separate templating module
This commit is contained in:
parent
8539d9b0f4
commit
817ff5c746
8 changed files with 32 additions and 22 deletions
0
openapi_core/templating/__init__.py
Normal file
0
openapi_core/templating/__init__.py
Normal file
0
openapi_core/templating/paths/__init__.py
Normal file
0
openapi_core/templating/paths/__init__.py
Normal file
27
openapi_core/templating/paths/finders.py
Normal file
27
openapi_core/templating/paths/finders.py
Normal 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
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
"""OpenAPI core validation util module"""
|
||||
"""OpenAPI core templating paths util module"""
|
||||
from six.moves.urllib.parse import urlparse
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from openapi_core.validation.util import path_qs
|
||||
from openapi_core.templating.paths.util import path_qs
|
||||
|
||||
|
||||
class TestPathQs(object):
|
Loading…
Reference in a new issue