Skip to content

Commit

Permalink
fix: Grape::Endpoint#merge_params now returns correct object (ruby-gr…
Browse files Browse the repository at this point in the history
  • Loading branch information
4ndv committed Oct 12, 2024
1 parent 7ec7bed commit 7ac816d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def merge_params(route)
route_params[key] = path.merge(params)
end

route.params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
route_params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
end

# Iterates over namespaces recursively
Expand Down
68 changes: 68 additions & 0 deletions spec/issues/942_route_params.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require 'spec_helper'

describe '#942 route param documentation' do
let(:documentation) { { format: 'uuid' } }

let(:app) do
docs = documentation

another_app = Class.new(Grape::API) do
get '/list' do
[]
end
end

Class.new(Grape::API) do
route_param :account_id, type: String, desc: 'id of account', documentation: docs do
mount another_app

get '/another-list' do
[]
end
end

add_swagger_documentation
end
end

subject do
get '/swagger_doc'
JSON.parse(last_response.body)
end

context 'when documenting route_param of mounted endpoint' do
let(:parameters) { subject['paths']['/{account_id}/list']['get']['parameters'] }

specify do
account_id_param = parameters.find { |param| param['name'] == 'account_id' }
expect(account_id_param['type']).to eq 'string'
expect(account_id_param['format']).to eq 'uuid'
expect(account_id_param['description']).to eq 'id of account'
end
end

context 'when documenting route_param of nested endpoint' do
let(:parameters) { subject['paths']['/{account_id}/another-list']['get']['parameters'] }

specify do
account_id_param = parameters.find { |param| param['name'] == 'account_id' }
expect(account_id_param['type']).to eq 'string'
expect(account_id_param['format']).to eq 'uuid'
expect(account_id_param['description']).to eq 'id of account'
end
end

context 'when documentation overrides description' do
let(:documentation) { { desc: 'another description' } }

let(:parameters) { subject['paths']['/{account_id}/list']['get']['parameters'] }

specify do
account_id_param = parameters.find { |param| param['name'] == 'account_id' }
expect(account_id_param['type']).to eq 'string'
expect(account_id_param['description']).to eq 'another description'
end
end
end

0 comments on commit 7ac816d

Please sign in to comment.