Skip to content

Commit d0d3faf

Browse files
committed
fixed falcon request validate and RefNode deepcopy
1 parent 17cc94a commit d0d3faf

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

swagger_py_codegen/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Version information."""
22

33
# The following line *must* be the last in the module, exactly as formatted:
4-
__version__ = "0.3.6"
4+
__version__ = "0.3.7"

swagger_py_codegen/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __eq__(self, other):
4545
return False
4646

4747
def __deepcopy__(self, memo):
48-
return RefNode(self._data, self.ref)
48+
return RefNode(copy.deepcopy(self._data), self.ref)
4949

5050
def copy(self):
5151
return RefNode(self._data, self.ref)

swagger_py_codegen/templates/falcon/blueprint.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from __future__ import absolute_import, print_function
44
import falcon
55

66
from .routes import routes
7-
from .validators import security
7+
from .validators import security, current
88

99

1010
@security.scopes_loader

swagger_py_codegen/templates/falcon/validators.tpl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def _path_to_endpoint(path):
3333
return _remove_characters(endpoint, '{}')
3434

3535

36+
class Current(object):
37+
38+
request = None
39+
40+
41+
current = Current()
42+
43+
3644
class JSONEncoder(json.JSONEncoder):
3745

3846
def default(self, o):
@@ -92,11 +100,12 @@ class FalconValidatorAdaptor(object):
92100

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

103+
current.request = req
95104
endpoint = _path_to_endpoint(req.uri_template)
96105
# scope
97106
if (endpoint, req.method) in scopes and not set(
98107
scopes[(endpoint, req.method)]).issubset(set(security.scopes)):
99-
falcon.HTTPUnauthorized('403403403')
108+
raise falcon.HTTPUnauthorized('invalid client')
100109
# data
101110
method = req.method
102111
if method == 'HEAD':
@@ -113,11 +122,11 @@ def request_validate(req, resp, resource, params):
113122
try:
114123
value = json.loads(body.decode('utf-8'))
115124
except (ValueError, UnicodeDecodeError):
116-
raise falcon.HTTPError(falcon.HTTP_753,
117-
'Malformed JSON',
118-
'Could not decode the request body. The '
119-
'JSON was incorrect or not encoded as '
120-
'UTF-8.')
125+
raise falcon.HTTPUnprocessableEntity(
126+
'Malformed JSON',
127+
'Could not decode the request body. The '
128+
'JSON was incorrect or not encoded as '
129+
'UTF-8.')
121130
if value is None:
122131
value = MultiDict()
123132
validator = FalconValidatorAdaptor(schema)

0 commit comments

Comments
 (0)