-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set valid consumes if file parameter
- Loading branch information
1 parent
1eb9fe6
commit eba6cb2
Showing
5 changed files
with
71 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module GrapeSwagger | ||
module DocMethods | ||
class FileParams | ||
class << self | ||
def includes_file_param?(params) | ||
return params.any? { |x| x[:type] == 'file' } | ||
end | ||
|
||
end | ||
|
||
def to_formdata(params) | ||
params.each { |x| x[:in] = 'formData' if x[:in] == 'body' } | ||
end | ||
end | ||
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
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,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe '#881 handle file params' do | ||
let(:app) do | ||
Class.new(Grape::API) do | ||
namespace :issue_881 do | ||
params do | ||
requires :upload, type: File | ||
end | ||
|
||
post do | ||
present params | ||
end | ||
end | ||
|
||
add_swagger_documentation format: :json | ||
end | ||
end | ||
|
||
subject do | ||
get '/swagger_doc' | ||
JSON.parse(last_response.body) | ||
end | ||
|
||
let(:consumes) { subject['paths']['/issue_881']['post']['consumes'] } | ||
let(:parameters) { subject['paths']['/issue_881']['post']['parameters'] } | ||
|
||
specify do | ||
expect(consumes).to eql( | ||
["application/x-www-form-urlencoded", "multipart/form-data"] | ||
) | ||
expect(parameters).to eql( | ||
[{"in"=>"formData", "name"=>"upload", "required"=>true, "type"=>"file"}] | ||
) | ||
end | ||
end |