Skip to content

Commit f18258c

Browse files
Add support for file uploads, and proper paramType.
Fileupload is working when type is defined as Rack::Multipart::UploadedFile in grape, and when using swagger from this branch: https://github.com/tim-vandecasteele/swagger-ui/tree/add_support_for_files If pull request (42)[swagger-api/swagger-ui#42] is accepted, it should land in grape master.
1 parent a3dc776 commit f18258c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/grape-swagger.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def self.setup(options)
7878
:summary => route.route_description || '',
7979
:nickname => Random.rand(1000000),
8080
:httpMethod => route.route_method,
81-
:parameters => parse_params(route.route_params)
81+
:parameters => parse_params(route.route_params, route.route_path, route.route_method)
8282
}]
8383
}
8484
end
@@ -95,12 +95,14 @@ def self.setup(options)
9595

9696

9797
helpers do
98-
def parse_params(params)
98+
def parse_params(params, path, method)
9999
params.map do |param, value|
100+
value[:type] = 'file' if value.is_a?(Hash) && value[:type] == 'Rack::Multipart::UploadedFile'
101+
100102
dataType = value.is_a?(Hash) ? value[:type]||'String' : 'String'
101103
description = value.is_a?(Hash) ? value[:desc] : ''
102104
required = value.is_a?(Hash) ? !!value[:required] : false
103-
paramType = 'path'
105+
paramType = path.match(":#{param}") ? 'path' : (method == 'POST') ? 'body' : 'query'
104106
{
105107
paramType: paramType,
106108
name: param,

0 commit comments

Comments
 (0)