Skip to content

Commit

Permalink
Remove Flask references (spec-first#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcaricio authored and hjacobs committed Apr 5, 2017
1 parent 067ad1b commit a95b986
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion connexion/decorators/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def wrapper(request):
class EndOfRequestLifecycleDecorator(BaseDecorator):
"""Manages the lifecycle of the request internally in Connexion.
Filter the ConnexionRequest instance to return the corresponding
flask.Response object.
framework specific object.
"""

def __init__(self, api, mimetype):
Expand Down
12 changes: 3 additions & 9 deletions connexion/decorators/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def wrapper(request):
if all_json(self.consumes):
data = request.json

# flask does not process json if the Content-Type header is not equal to "application/json"
if data is None and len(request.body) > 0 and not self.is_null_value_valid:
# the body has contents that were not parsed as JSON
return problem(415,
"Unsupported Media Type",
"Invalid Content-type ({content_type}), expected JSON data".format(
Expand All @@ -125,10 +125,7 @@ def wrapper(request):
return wrapper

def validate_schema(self, data, url):
"""
:type data: dict
:rtype: flask.Response | None
"""
# type: (dict, AnyStr) -> Union[ConnexionResponse, None]
if self.is_null_value_valid and is_null(data):
return None

Expand All @@ -154,10 +151,7 @@ def __init__(self, schema, validator=None):
self.validator = ValidatorClass(schema, format_checker=draft4_format_checker)

def validate_schema(self, data, url):
"""
:type data: dict
:rtype: flask.Response | None
"""
# type: (dict, AnyStr) -> Union[ConnexionResponse, None]
try:
self.validator.validate(data)
except ValidationError as exception:
Expand Down
4 changes: 2 additions & 2 deletions connexion/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_mimetype(self):
def _request_begin_lifecycle_decorator(self):
"""
Transforms the result of the operation handler in a internal
representation (connexion.decorators.ConnexionRequest) to be
representation (connexion.request.ConnexionRequest) to be
used by internal Connexion decorators.
:rtype: types.FunctionType
Expand All @@ -116,7 +116,7 @@ def _request_end_lifecycle_decorator(self):
"""
Guarantees that instead of the internal representation of the
operation handler response
(connexion.decorators.ConnexionRequest) a flask.Response
(connexion.request.ConnexionRequest) a framework specific
object is returned.
:rtype: types.FunctionType
"""
Expand Down
9 changes: 2 additions & 7 deletions connexion/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def problem(status, title, detail, type=None, instance=None, headers=None, ext=N
:type headers: dict | None
:param ext: Extension members to include in the body
:type ext: dict | None
:return: Json serialized error response
:rtype: flask.Response
:return: error response
:rtype: ConnexionResponse
"""
if not type:
type = 'about:blank'
Expand All @@ -36,11 +36,6 @@ def problem(status, title, detail, type=None, instance=None, headers=None, ext=N
if ext:
problem_response.update(ext)

# We serialize here because even if the default content type is
# not set to JSON, which means that the
# `decorators.produces.Jsonifier` will not be added to the request
# life-cycle (so we cannot rely on that serialization), we will
# return a problem payload in JSON format.
mimetype = content_type = 'application/problem+json'
return ConnexionResponse(status, mimetype, content_type,
body=problem_response,
Expand Down

0 comments on commit a95b986

Please sign in to comment.