Skip to content

Commit

Permalink
Parameters delimited by dash cause exception (#586)
Browse files Browse the repository at this point in the history
* Fixed range parameters delimited by dash

* fixed rubocop offense

* updates for requested changes - renamed spec and showed operationId value in spec

* Changelog updated
  • Loading branch information
risa authored and peter scholz committed Feb 28, 2017
1 parent 26e6d93 commit 79052e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

* Your contribution here.

Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/operation_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def build(route, path = nil)

def manipulate(path)
operation = path.split('/').map(&:capitalize).join
operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-')
operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation[/\-(\w)/]
operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_')
operation.gsub!(/\.(\w)/, &:upcase).delete!('.') if operation.include?('.')
if path.include?('{')
Expand Down
24 changes: 24 additions & 0 deletions spec/issues/587_range_parameter_delimited_by_dash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

describe '#587 process route with parameters delimited by dash' do
let(:app) do
Class.new(Grape::API) do
namespace :range_parameter do
desc 'Get a array with range'
get '/range/:range_start-:range_end' do
present []
end
end

add_swagger_documentation format: :json
end
end

subject do
get '/swagger_doc'
JSON.parse(last_response.body)['paths']
end

specify { expect(subject.keys).to include '/range_parameter/range/{range_start}-{range_end}' }
specify { expect(subject['/range_parameter/range/{range_start}-{range_end}']['get']['operationId']).to eql 'getRangeParameterRangeRangeStart-RangeEnd' }
end

0 comments on commit 79052e3

Please sign in to comment.