diff --git a/CHANGELOG.md b/CHANGELOG.md index c84d381b..5bc90d50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### Features +* [#874](https://github.com/ruby-grape/grape-swagger/pull/874): Add support for wildcard segments path parameters - [@spaceraccoon](https://github.com/spaceraccoon) * Your contribution here. #### Fixes diff --git a/lib/grape-swagger/doc_methods/path_string.rb b/lib/grape-swagger/doc_methods/path_string.rb index 1fc02aa1..17986b3d 100644 --- a/lib/grape-swagger/doc_methods/path_string.rb +++ b/lib/grape-swagger/doc_methods/path_string.rb @@ -12,6 +12,7 @@ def build(route, options = {}) # ... format path params path.gsub!(/:(\w+)/, '{\1}') + path.gsub!(/\*(\w+)/, '{\1}') # set item from path, this could be used for the definitions object path_name = path.gsub(%r{/{(.+?)}}, '').split('/').last diff --git a/spec/issues/873_wildcard_segments_path_parameters.rb b/spec/issues/873_wildcard_segments_path_parameters.rb new file mode 100644 index 00000000..8b1682fa --- /dev/null +++ b/spec/issues/873_wildcard_segments_path_parameters.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe '#873 detect wildcard segments as path parameters' do + let(:app) do + Class.new(Grape::API) do + resource :books do + get '*section/:title' do + { message: 'hello world' } + end + end + + add_swagger_documentation + end + end + let(:parameters) { subject['paths']['/books/{section}/{title}']['get']['parameters'] } + + subject do + get '/swagger_doc' + JSON.parse(last_response.body) + end + + specify do + section_param = parameters.find { |param| param['name'] == 'section' } + expect(section_param['in']).to eq 'path' + end +end