Skip to content

Commit 0ffe539

Browse files
committed
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.
1 parent 2e285ed commit 0ffe539

File tree

2 files changed

+8
-4
lines changed
  • modules/swagger-codegen/src/main/resources/ruby/swagger
  • samples/client/petstore/ruby/lib/swagger_client/swagger

2 files changed

+8
-4
lines changed

modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,16 @@ module {{moduleName}}
120120
# For form parameters, remove empty value
121121
def outgoing_body
122122
# http form
123-
if @body.nil? && @form_params && !@form_params.empty?
123+
if headers['Content-Type'] == 'application/x-www-form-urlencoded'
124124
data = form_params.dup
125125
data.each do |key, value|
126126
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
127127
end
128128
data
129-
else # http body is JSON
129+
elsif @body # http body is JSON
130130
@body.is_a?(String) ? @body : @body.to_json
131+
else
132+
nil
131133
end
132134
end
133135

samples/client/petstore/ruby/lib/swagger_client/swagger/request.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,16 @@ def body=(value)
119119
# For form parameters, remove empty value
120120
def outgoing_body
121121
# http form
122-
if @body.nil? && @form_params && !@form_params.empty?
122+
if headers['Content-Type'] == 'application/x-www-form-urlencoded'
123123
data = form_params.dup
124124
data.each do |key, value|
125125
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
126126
end
127127
data
128-
else # http body is JSON
128+
elsif @body # http body is JSON
129129
@body.is_a?(String) ? @body : @body.to_json
130+
else
131+
nil
130132
end
131133
end
132134

0 commit comments

Comments
 (0)