Skip to content

Commit

Permalink
fixed falcon request validate and RefNode deepcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
gusibi committed Nov 8, 2018
1 parent 17cc94a commit d0d3faf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion swagger_py_codegen/_version.py
@@ -1,4 +1,4 @@
"""Version information."""

# The following line *must* be the last in the module, exactly as formatted:
__version__ = "0.3.6"
__version__ = "0.3.7"
2 changes: 1 addition & 1 deletion swagger_py_codegen/parser.py
Expand Up @@ -45,7 +45,7 @@ def __eq__(self, other):
return False

def __deepcopy__(self, memo):
return RefNode(self._data, self.ref)
return RefNode(copy.deepcopy(self._data), self.ref)

def copy(self):
return RefNode(self._data, self.ref)
Expand Down
2 changes: 1 addition & 1 deletion swagger_py_codegen/templates/falcon/blueprint.tpl
Expand Up @@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function
import falcon

from .routes import routes
from .validators import security
from .validators import security, current


@security.scopes_loader
Expand Down
21 changes: 15 additions & 6 deletions swagger_py_codegen/templates/falcon/validators.tpl
Expand Up @@ -33,6 +33,14 @@ def _path_to_endpoint(path):
return _remove_characters(endpoint, '{}')


class Current(object):

request = None


current = Current()


class JSONEncoder(json.JSONEncoder):

def default(self, o):
Expand Down Expand Up @@ -92,11 +100,12 @@ class FalconValidatorAdaptor(object):

def request_validate(req, resp, resource, params):

current.request = req
endpoint = _path_to_endpoint(req.uri_template)
# scope
if (endpoint, req.method) in scopes and not set(
scopes[(endpoint, req.method)]).issubset(set(security.scopes)):
falcon.HTTPUnauthorized('403403403')
raise falcon.HTTPUnauthorized('invalid client')
# data
method = req.method
if method == 'HEAD':
Expand All @@ -113,11 +122,11 @@ def request_validate(req, resp, resource, params):
try:
value = json.loads(body.decode('utf-8'))
except (ValueError, UnicodeDecodeError):
raise falcon.HTTPError(falcon.HTTP_753,
'Malformed JSON',
'Could not decode the request body. The '
'JSON was incorrect or not encoded as '
'UTF-8.')
raise falcon.HTTPUnprocessableEntity(
'Malformed JSON',
'Could not decode the request body. The '
'JSON was incorrect or not encoded as '
'UTF-8.')
if value is None:
value = MultiDict()
validator = FalconValidatorAdaptor(schema)
Expand Down

0 comments on commit d0d3faf

Please sign in to comment.