Skip to content

Commit 3af0f34

Browse files
committed
Add support for wildcard segments path parameters
1 parent 1eb9fe6 commit 3af0f34

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#### Features
44

5+
* [#874](https://github.com/ruby-grape/grape-swagger/pull/874): Add support for wildcard segments path parameters - [@spaceraccoon](https://github.com/spaceraccoon)
56
* Your contribution here.
67

78
#### Fixes

lib/grape-swagger/doc_methods/path_string.rb

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def build(route, options = {})
1212

1313
# ... format path params
1414
path.gsub!(/:(\w+)/, '{\1}')
15+
path.gsub!(/\*(\w+)/, '{\1}')
1516

1617
# set item from path, this could be used for the definitions object
1718
path_name = path.gsub(%r{/{(.+?)}}, '').split('/').last
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe '#873 detect wildcard segments as path parameters' do
6+
let(:app) do
7+
Class.new(Grape::API) do
8+
resource :books do
9+
get '*section/:title' do
10+
{ message: 'hello world' }
11+
end
12+
end
13+
14+
add_swagger_documentation
15+
end
16+
end
17+
let(:parameters) { subject['paths']['/books/{section}/{title}']['get']['parameters'] }
18+
19+
subject do
20+
get '/swagger_doc'
21+
JSON.parse(last_response.body)
22+
end
23+
24+
specify do
25+
section_param = parameters.find { |param| param['name'] == 'section' }
26+
expect(section_param['in']).to eq 'path'
27+
end
28+
end

0 commit comments

Comments
 (0)