172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/betterdocs/generator/swagger.rb', line 172
def get_request_url_slugs(request)
slugs = %r{
(?<method>GET|POST|PUT|DELETE|OPTIONS)\s+
(?<protocol>https?)://
(?<host>[a-z.]+)/
(?<lang>[a-z]{2})/api_
(?<ver>v[0-9]+)/
(?<path>[\w/-]+\.json?)
}x.match(request).named_captures.transform_keys(&:to_sym)
slugs[:params] = []
split = slugs[:path].split('/')
path_cmp = split.map.with_index do |cmp, i|
unless i.even?
suffix = cmp['.json'] || ''
name = "#{split[i - 1]}_id"
cmp = "{#{name}}#{suffix}"
param = { name: name, type: get_path_param_slug_type(cmp.gsub('.json', '')) }
slugs[:params].push(param)
end
cmp
end
slugs[:method] = slugs[:method].downcase
slugs[:path] = "/#{path_cmp.join('/')}"
slugs
end
|