Skip to content

Commit eca701f

Browse files
committed
Not good to inject anything into route.path. A copy into the local variable is better.
.
1 parent 948b0de commit eca701f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/grape-swagger/doc_methods/path_string.rb

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ module DocMethods
33
class PathString
44
class << self
55
def build(route, options = {})
6+
path = route.path
67
# always removing format
7-
route.path.sub!(/\(\.\w+?\)$/, '')
8-
route.path.sub!('(.:format)', '')
8+
path.sub!(/\(\.\w+?\)$/, '')
9+
path.sub!('(.:format)', '')
910

1011
# ... format path params
11-
route.path.gsub!(/:(\w+)/, '{\1}')
12+
path.gsub!(/:(\w+)/, '{\1}')
1213

1314
# set item from path, this could be used for the definitions object
14-
item = route.path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item'
15+
item = path.gsub(%r{/{(.+?)}}, '').split('/').last.singularize.underscore.camelize || 'Item'
1516

1617
if route.version && options[:add_version]
17-
route.path.sub!('{version}', route.version.to_s)
18+
path.sub!('{version}', route.version.to_s)
1819
else
19-
route.path.sub!('/{version}', '')
20+
path.sub!('/{version}', '')
2021
end
2122

22-
route.path.prepend(GrapeSwagger::DocMethods::OptionalObject.build(:base_path, options)) if options[:add_base_path]
23+
path = "#{GrapeSwagger::DocMethods::OptionalObject.build(:base_path, options)}#{path}" if options[:add_base_path]
2324

24-
[item, route.path.start_with?('/') ? route.path : "/#{route.path}"]
25+
[item, path.start_with?('/') ? path : "/#{path}"]
2526
end
2627
end
2728
end

0 commit comments

Comments
 (0)