From 79052e3ea70746600b2cc5bcce92c28a218a6ab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Ko=C5=99=C3=ADnek?= Date: Tue, 28 Feb 2017 01:12:41 +0100 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + lib/grape-swagger/doc_methods/operation_id.rb | 2 +- ..._range_parameter_delimited_by_dash_spec.rb | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 spec/issues/587_range_parameter_delimited_by_dash_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c54ad7..9cc8cd3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/grape-swagger/doc_methods/operation_id.rb b/lib/grape-swagger/doc_methods/operation_id.rb index c194b0ba..4e028e22 100644 --- a/lib/grape-swagger/doc_methods/operation_id.rb +++ b/lib/grape-swagger/doc_methods/operation_id.rb @@ -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?('{') diff --git a/spec/issues/587_range_parameter_delimited_by_dash_spec.rb b/spec/issues/587_range_parameter_delimited_by_dash_spec.rb new file mode 100644 index 00000000..e1c65b27 --- /dev/null +++ b/spec/issues/587_range_parameter_delimited_by_dash_spec.rb @@ -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