Skip to content

Commit

Permalink
Add support for wildcard segments path parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceraccoon committed Oct 13, 2022
1 parent 1eb9fe6 commit 3262908
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger/doc_methods/path_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions spec/issues/873_wildcard_segments_path_parameters.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3262908

Please sign in to comment.