Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ruby-core-lib): fix returning nil instead of empty request params #21

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apimatic_core.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'apimatic_core'
s.version = '0.3.0'
s.version = '0.3.1'
s.summary = 'A library that contains apimatic-apimatic-core logic and utilities for consuming REST APIs using Python SDKs generated '\
'by APIMatic.'
s.description = 'The APIMatic Core libraries provide a stable runtime that powers all the functionality of SDKs.'\
Expand Down
3 changes: 1 addition & 2 deletions lib/apimatic-core/request_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,14 @@ def process_body
_form_params.merge!(@form_params) if _has_form_params
_form_params.merge!(@multipart_params) if _has_multipart_param
_form_params.merge!(@additional_form_params) if _has_additional_form_params
# TODO: add Array serialization format support while writing the POC
return ApiHelper.form_encode_parameters(_form_params, @array_serialization_format)
elsif _has_body_param && _has_body_serializer
return @body_serializer.call(resolve_body_param)
elsif _has_body_param && !_has_body_serializer
return resolve_body_param
end

{}
nil
end

# Processes the part of a multipart request and assign appropriate part value and its content-type.
Expand Down
23 changes: 23 additions & 0 deletions test/test-apimatic-core/request_builder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ def test_body_param
assert(actual.parameters == "value")
end

def test_no_body_request
actual = MockHelper.create_basic_request_builder
.path('http://localhost/test/{key}')
.http_method(HttpMethod::GET)
.query_param(MockHelper.new_parameter("query", key: "key"))
.template_param(MockHelper.new_parameter("template", key: "key"))
.header_param(MockHelper.new_parameter("header", key: "key"))
.build({})

assert_nil(actual.parameters)

actual = MockHelper.create_basic_request_builder
.path('http://localhost/test/{key}')
.http_method(HttpMethod::GET)
.query_param(MockHelper.new_parameter("query", key: "key"))
.template_param(MockHelper.new_parameter("template", key: "key"))
.header_param(MockHelper.new_parameter("header", key: "key"))
.form_param(MockHelper.new_parameter("form_param", key: "key"))
.build({})

assert(actual.parameters["key"] == "form_param")
end

def test_body_param_file
file = File::open("README.md", "r")

Expand Down