Skip to content

Commit

Permalink
Don't include fixed named captures as route params
Browse files Browse the repository at this point in the history
  • Loading branch information
namusyaka committed Apr 9, 2016
1 parent 05cd6f7 commit b95f99d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/grape/router/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Router
class Route
ROUTE_ATTRIBUTE_REGEXP = /route_([_a-zA-Z]\w*)/.freeze
SOURCE_LOCATION_REGEXP = /^(.*?):(\d+?)(?::in `.+?')?$/.freeze
FIXED_NAMED_CAPTURES = %w[format version].freeze

attr_accessor :pattern, :translator, :app, :index, :regexp

Expand Down Expand Up @@ -81,7 +82,7 @@ def params(input = nil)
default = pattern.named_captures.keys.each_with_object({}) do |key, defaults|
defaults[key] = ''
end
default.delete_if { |key, _| key == 'format' }.merge(translator.params)
default.delete_if { |key, _| FIXED_NAMED_CAPTURES.include?(key) }.merge(translator.params)
else
parsed = pattern.params(input)
parsed ? parsed.delete_if { |_, value| value.nil? }.symbolize_keys : {}
Expand Down
7 changes: 7 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,13 @@ def static
expect(route.route_foo).to be_nil
expect(route.params).to eq({})
end
it 'has params which does not include format and version as named captures' do
subject.version :v1, using: :path
subject.get :first do; end
param_keys = subject.routes.first.params.keys
expect(param_keys).not_to include('format')
expect(param_keys).not_to include('version')
end
it 'describes methods separately' do
subject.desc 'first method'
subject.get :first do; end
Expand Down

0 comments on commit b95f99d

Please sign in to comment.