-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi type and documentation hash (#444)
* multi type parameter default to first type when :type and :default are provided in a documenation hash they override grape :type and :default * rubocop style * changelog style * test multi type only if grape >= 0.14 * rubocop style * test for muli type with grape<0.14
- Loading branch information
Showing
7 changed files
with
208 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Params Multi Types' do | ||
def app | ||
Class.new(Grape::API) do | ||
format :json | ||
|
||
params do | ||
if Grape::VERSION < '0.14' | ||
requires :input, type: [String, Integer] | ||
else | ||
requires :input, types: [String, Integer] | ||
end | ||
requires :another_input, type: [String, Integer] | ||
end | ||
post :action do | ||
end | ||
|
||
add_swagger_documentation | ||
end | ||
end | ||
|
||
subject do | ||
get '/swagger_doc/action' | ||
expect(last_response.status).to eq 200 | ||
body = JSON.parse last_response.body | ||
body['paths']['/action']['post']['parameters'] | ||
end | ||
|
||
it 'reads param type correctly' do | ||
expect(subject).to eq [ | ||
{ | ||
'in' => 'formData', | ||
'name' => 'input', | ||
'type' => 'string', | ||
'required' => true | ||
}, | ||
{ | ||
'in' => 'formData', | ||
'name' => 'another_input', | ||
'type' => 'string', | ||
'required' => true | ||
} | ||
] | ||
end | ||
|
||
describe 'header params' do | ||
def app | ||
Class.new(Grape::API) do | ||
format :json | ||
|
||
desc 'Some API', headers: { 'My-Header' => { required: true, description: 'Set this!' } } | ||
params do | ||
if Grape::VERSION < '0.14' | ||
requires :input, type: [String, Integer] | ||
else | ||
requires :input, types: [String, Integer] | ||
end | ||
requires :another_input, type: [String, Integer] | ||
end | ||
post :action do | ||
end | ||
|
||
add_swagger_documentation | ||
end | ||
end | ||
|
||
it 'has consistent types' do | ||
types = subject.map { |param| param['type'] } | ||
expect(types).to eq(%w(string string string)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters