Skip to content

Commit 79052e3

Browse files
risapeter scholz
authored and
peter scholz
committed
Parameters delimited by dash cause exception (#586)
* Fixed range parameters delimited by dash * fixed rubocop offense * updates for requested changes - renamed spec and showed operationId value in spec * Changelog updated
1 parent 26e6d93 commit 79052e3

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
* [#580](https://github.com/ruby-grape/grape-swagger/pull/580): Issue #578: fixes duplicated path params - [@LeFnord](https://github.com/LeFnord).
1212
* [#585](https://github.com/ruby-grape/grape-swagger/pull/585): Issue #584: do not mutate route.path - [@LeFnord](https://github.com/LeFnord).
13+
* [#586](https://github.com/ruby-grape/grape-swagger/pull/586): Issue #587: Parameters delimited by dash cause exception - [@risa](https://github.com/risa).
1314

1415
* Your contribution here.
1516

lib/grape-swagger/doc_methods/operation_id.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def build(route, path = nil)
1414

1515
def manipulate(path)
1616
operation = path.split('/').map(&:capitalize).join
17-
operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-')
17+
operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation[/\-(\w)/]
1818
operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_')
1919
operation.gsub!(/\.(\w)/, &:upcase).delete!('.') if operation.include?('.')
2020
if path.include?('{')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'spec_helper'
2+
3+
describe '#587 process route with parameters delimited by dash' do
4+
let(:app) do
5+
Class.new(Grape::API) do
6+
namespace :range_parameter do
7+
desc 'Get a array with range'
8+
get '/range/:range_start-:range_end' do
9+
present []
10+
end
11+
end
12+
13+
add_swagger_documentation format: :json
14+
end
15+
end
16+
17+
subject do
18+
get '/swagger_doc'
19+
JSON.parse(last_response.body)['paths']
20+
end
21+
22+
specify { expect(subject.keys).to include '/range_parameter/range/{range_start}-{range_end}' }
23+
specify { expect(subject['/range_parameter/range/{range_start}-{range_end}']['get']['operationId']).to eql 'getRangeParameterRangeRangeStart-RangeEnd' }
24+
end

0 commit comments

Comments
 (0)