Added support for Rack::Multipart::UploadedFile parameters, fixes #47.
This commit is contained in:
parent
a19a63e8d2
commit
04566fcdb4
|
|
@ -1,5 +1,6 @@
|
|||
### Next Release
|
||||
|
||||
* [#139](https://github.com/tim-vandecasteele/grape-swagger/pull/139): Added support for `Rack::Multipart::UploadedFile` parameters - [@timgluz](https://github.com/timgluz).
|
||||
* [#136](https://github.com/tim-vandecasteele/grape-swagger/pull/136), [#94](https://github.com/tim-vandecasteele/grape-swagger/pull/94): Recurse combination of namespaces when using mounted apps - [@renier](https://github.com/renier).
|
||||
* [#100](https://github.com/tim-vandecasteele/grape-swagger/pull/100): Added ability to specify a nickname for an endpoint - [@lhorne](https://github.com/lhorne).
|
||||
* [#94](https://github.com/tim-vandecasteele/grape-swagger/pull/94): Added support for namespace descriptions - [@renier](https://github.com/renier).
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ module Grape
|
|||
def parse_params(params, path, method)
|
||||
params ||= []
|
||||
params.map do |param, value|
|
||||
value[:type] = 'File' if value.is_a?(Hash) && value[:type] == 'Rack::Multipart::UploadedFile'
|
||||
value[:type] = 'File' if value.is_a?(Hash) && ['Rack::Multipart::UploadedFile', 'Hash'].include?(value[:type])
|
||||
items = {}
|
||||
|
||||
raw_data_type = value.is_a?(Hash) ? (value[:type] || 'string').to_s : 'string'
|
||||
|
|
|
|||
|
|
@ -46,6 +46,44 @@ describe 'helpers' do
|
|||
]
|
||||
end
|
||||
|
||||
it 'parses file param' do
|
||||
params = {
|
||||
rack: {
|
||||
type: 'Rack::Multipart::UploadedFile',
|
||||
desc: 'rack file',
|
||||
datafile: 'content',
|
||||
required: true
|
||||
},
|
||||
rails: {
|
||||
type: 'Hash',
|
||||
desc: 'rails file',
|
||||
datafile: 'content',
|
||||
required: true
|
||||
}
|
||||
}
|
||||
path = '/coolness'
|
||||
method = 'POST'
|
||||
expect(subject.parse_params(params, path, method)).to eq [
|
||||
{
|
||||
paramType: 'body',
|
||||
name: :rack,
|
||||
description: 'rack file',
|
||||
type: 'File',
|
||||
required: true,
|
||||
allowMultiple: false
|
||||
},
|
||||
{
|
||||
paramType: 'body',
|
||||
name: :rails,
|
||||
description: 'rails file',
|
||||
type: 'File',
|
||||
required: true,
|
||||
allowMultiple: false
|
||||
}
|
||||
]
|
||||
|
||||
end
|
||||
|
||||
context 'custom type' do
|
||||
before :all do
|
||||
class CustomType
|
||||
|
|
|
|||
11
test/api.rb
11
test/api.rb
|
|
@ -45,6 +45,17 @@ class Api < Grape::API
|
|||
get do
|
||||
@@splines.values
|
||||
end
|
||||
|
||||
# TEST api for testing uploading
|
||||
# curl --form file=@splines.png http://localhost:9292/splines/upload
|
||||
desc 'Update image'
|
||||
post 'upload' do
|
||||
filename = params[:file][:filename]
|
||||
content_type 'application/octet-stream'
|
||||
env['api.format'] = :binary # there's no formatter for :binary, data will be returned "as is"
|
||||
header 'Content-Disposition', "attachment; filename*=UTF-8''#{URI.escape(filename)}"
|
||||
params[:file][:tempfile].read
|
||||
end
|
||||
end
|
||||
|
||||
add_swagger_documentation
|
||||
|
|
|
|||
Loading…
Reference in New Issue