Bug fix: "null" was used as post body for empty form parameters

The form parameters could be empty when all of them are optional and no
values are assigned to them.
This commit is contained in:
xhh
2015-06-03 21:17:42 +08:00
parent 2e285ed562
commit 0ffe53933d
2 changed files with 8 additions and 4 deletions

View File

@@ -120,14 +120,16 @@ module {{moduleName}}
# For form parameters, remove empty value
def outgoing_body
# http form
if @body.nil? && @form_params && !@form_params.empty?
if headers['Content-Type'] == 'application/x-www-form-urlencoded'
data = form_params.dup
data.each do |key, value|
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
end
data
else # http body is JSON
elsif @body # http body is JSON
@body.is_a?(String) ? @body : @body.to_json
else
nil
end
end

View File

@@ -119,14 +119,16 @@ module SwaggerClient
# For form parameters, remove empty value
def outgoing_body
# http form
if @body.nil? && @form_params && !@form_params.empty?
if headers['Content-Type'] == 'application/x-www-form-urlencoded'
data = form_params.dup
data.each do |key, value|
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
end
data
else # http body is JSON
elsif @body # http body is JSON
@body.is_a?(String) ? @body : @body.to_json
else
nil
end
end