Skip to content

Commit 4330a5c

Browse files
authored
Fix path with groups parsing (skip + warn) (#64)
1 parent a2910a9 commit 4330a5c

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

README.rst

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ What’s new?
110110
-----------
111111

112112

113+
Version 1.4.4
114+
~~~~~~~~~~~~~
115+
116+
- Fix path parsing with groups (skip + warning) [issue-58](https://github.com/mrk-andreev/tornado-swagger/issues/58)
117+
113118
Version 1.4.3
114119
~~~~~~~~~~~~~
115120

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ max-args=5
4040
max-attributes=10
4141
max-bool-expr=5
4242
max-module-lines=500
43-
max-nested-blocks=2
43+
max-nested-blocks=3
4444
max-public-methods=30
4545
max-returns=5
4646
max-statements=30

tornado_swagger/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.4.3"
1+
__version__ = "1.4.4"

tornado_swagger/_builders.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import re
77
import typing
8+
import warnings
89

910
import tornado.web
1011
import yaml
@@ -89,8 +90,13 @@ def _format_handler_path(route, method):
8990
brackets_regex = re.compile(r"\(.*?\)")
9091
parameters = _extract_parameters_names(route.target, route.regex.groups, method)
9192
route_pattern = route.regex.pattern
93+
brackets = brackets_regex.findall(route_pattern)
9294

93-
for i, entity in enumerate(brackets_regex.findall(route_pattern)):
95+
if len(brackets) != len(parameters):
96+
warnings.warn("Illegal route. route.regex.groups does not match all parameters. Route = " + str(route))
97+
return None
98+
99+
for i, entity in enumerate(brackets):
94100
route_pattern = route_pattern.replace(entity, "{%s}" % parameters[i], 1)
95101

96102
return route_pattern[:-1]
@@ -121,7 +127,11 @@ def _extract_paths(routes):
121127

122128
for route in routes:
123129
for method_name, method_description in _build_doc_from_func_doc(route.target).items():
124-
paths[_format_handler_path(route, method_name)].update({method_name: method_description})
130+
path_handler = _format_handler_path(route, method_name)
131+
if path_handler is None:
132+
continue
133+
134+
paths[path_handler].update({method_name: method_description})
125135

126136
return paths
127137

0 commit comments

Comments
 (0)