Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for wildcard segments path parameters #874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_spec.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