mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-10 04:19:37 +00:00
refactor param names
This commit is contained in:
@@ -58,12 +58,12 @@ class Api(object):
|
||||
Single API that corresponds to a flask blueprint
|
||||
"""
|
||||
|
||||
def __init__(self, swagger_yaml_path, base_url=None, arguments=None,
|
||||
def __init__(self, specification, base_url=None, arguments=None,
|
||||
swagger_json=None, swagger_ui=None, swagger_path=None, swagger_url=None,
|
||||
validate_responses=False, strict_validation=False, resolver=None,
|
||||
auth_all_paths=False, debug=False, resolver_error_handler=None):
|
||||
"""
|
||||
:type swagger_yaml_path: pathlib.Path
|
||||
:type specification: pathlib.Path | dict
|
||||
:type base_url: str | None
|
||||
:type arguments: dict | None
|
||||
:type swagger_json: bool
|
||||
@@ -81,8 +81,8 @@ class Api(object):
|
||||
"""
|
||||
self.debug = debug
|
||||
self.resolver_error_handler = resolver_error_handler
|
||||
logger.debug('Loading specification: %s', swagger_yaml_path,
|
||||
extra={'swagger_yaml': swagger_yaml_path,
|
||||
logger.debug('Loading specification: %s', specification,
|
||||
extra={'swagger_yaml': specification,
|
||||
'base_url': base_url,
|
||||
'arguments': arguments,
|
||||
'swagger_ui': swagger_ui,
|
||||
@@ -90,11 +90,11 @@ class Api(object):
|
||||
'swagger_url': swagger_url,
|
||||
'auth_all_paths': auth_all_paths})
|
||||
|
||||
if isinstance(swagger_yaml_path, dict):
|
||||
self.specification = swagger_yaml_path
|
||||
if isinstance(specification, dict):
|
||||
self.specification = specification
|
||||
else:
|
||||
self.swagger_yaml_path = pathlib.Path(swagger_yaml_path)
|
||||
self.load_spec_from_file(arguments, swagger_yaml_path)
|
||||
self.specification = pathlib.Path(specification)
|
||||
self.load_spec_from_file(arguments, specification)
|
||||
|
||||
self.specification = compatibility_layer(self.specification)
|
||||
logger.debug('Read specification', extra={'spec': self.specification})
|
||||
@@ -309,10 +309,10 @@ class Api(object):
|
||||
"""
|
||||
return flask.send_from_directory(str(self.swagger_path), filename)
|
||||
|
||||
def load_spec_from_file(self, arguments, swagger_yaml_path):
|
||||
def load_spec_from_file(self, arguments, specification):
|
||||
arguments = arguments or {}
|
||||
|
||||
with swagger_yaml_path.open(mode='rb') as swagger_yaml:
|
||||
with specification.open(mode='rb') as swagger_yaml:
|
||||
contents = swagger_yaml.read()
|
||||
try:
|
||||
swagger_template = contents.decode()
|
||||
|
||||
@@ -84,14 +84,14 @@ class App(object):
|
||||
exception = werkzeug.exceptions.InternalServerError()
|
||||
return problem(title=exception.name, detail=exception.description, status=exception.code)
|
||||
|
||||
def add_api(self, swagger_file, base_path=None, arguments=None, auth_all_paths=None, swagger_json=None,
|
||||
def add_api(self, specification, base_path=None, arguments=None, auth_all_paths=None, swagger_json=None,
|
||||
swagger_ui=None, swagger_path=None, swagger_url=None, validate_responses=False,
|
||||
strict_validation=False, resolver=Resolver(), resolver_error=None):
|
||||
"""
|
||||
Adds an API to the application based on a swagger file
|
||||
Adds an API to the application based on a swagger file or API dict
|
||||
|
||||
:param swagger_file: swagger file with the specification
|
||||
:type swagger_file: pathlib.Path
|
||||
:param specification: swagger file with the specification | specification dict
|
||||
:type specification: pathlib.Path or dict
|
||||
:param base_path: base path where to add this api
|
||||
:type base_path: str | None
|
||||
:param arguments: api version specific arguments to replace on the specification
|
||||
@@ -130,17 +130,17 @@ class App(object):
|
||||
swagger_path = swagger_path if swagger_path is not None else self.swagger_path
|
||||
swagger_url = swagger_url if swagger_url is not None else self.swagger_url
|
||||
auth_all_paths = auth_all_paths if auth_all_paths is not None else self.auth_all_paths
|
||||
logger.debug('Adding API: %s', swagger_file)
|
||||
logger.debug('Adding API: %s', specification)
|
||||
# TODO test if base_url starts with an / (if not none)
|
||||
arguments = arguments or dict()
|
||||
arguments = dict(self.arguments, **arguments) # copy global arguments and update with api specfic
|
||||
|
||||
if isinstance(swagger_file, dict):
|
||||
yaml_path = swagger_file
|
||||
if isinstance(specification, dict):
|
||||
specification = specification
|
||||
else:
|
||||
yaml_path = self.specification_dir / swagger_file
|
||||
specification = self.specification_dir / specification
|
||||
|
||||
api = Api(swagger_yaml_path=yaml_path,
|
||||
api = Api(specification=specification,
|
||||
base_url=base_path, arguments=arguments,
|
||||
swagger_json=swagger_json,
|
||||
swagger_ui=swagger_ui,
|
||||
|
||||
@@ -54,7 +54,7 @@ def test_no_swagger_json_app(simple_api_spec_dir):
|
||||
assert swagger_json.status_code == 404
|
||||
|
||||
|
||||
def test_dic_as_yaml_path(simple_api_spec_dir):
|
||||
def test_dict_as_yaml_path(simple_api_spec_dir):
|
||||
|
||||
swagger_yaml_path = simple_api_spec_dir / 'swagger.yaml'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user