[BUG] [Ruby] `return_binary_data` NoMethodError
Created by: ckoegel
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When hitting an endpoint that returns media data, the API client attempts to deserialize the response body. Inside this deserialize function, if the return type is set to File
(the default) the function checks to see if the client is configured to return binary data or not. This if statement attempts to check the return_binary_data
attribute of the configuration object, which causes a NoMethodError
. This error also occurs when attempting to set the return_binary_data
attribute in the config. See examples below.
Inside the deserialize
function.
response = @api_instance_media.get_media_with_http_info(BW_ACCOUNT_ID, @media_file_name)
Failure/Error: if @config.return_binary_data == true
NoMethodError:
undefined method `return_binary_data' for #<Bandwidth::Configuration:0x00000001088049a0 @scheme="http", @host="localhost", @base_path="", @server_index=0, @server_operation_index={}, @server_variables={}, @server_operation_variables={}, @api_key={}, @api_key_prefix={}, @client_side_validation=true, @ssl_verify=true, @ssl_verify_mode=nil, @ssl_ca_file=nil, @ssl_client_cert=nil, @ssl_client_key=nil, @middlewares={}, @timeout=60, @return_binary_data=false, @params_encoder=nil, @debugging=false, @inject_format=false, @force_ending_format=false, @logger=#<Logger:0x0000000108a67fd0 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x0000000108a67e90 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x0000000108a67cb0 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @binmode=false, @mon_data=#<Monitor:0x0000000108a67be8>, @mon_data_owner_object_id=4660>>, @username="***", @password="***">
if @config.return_binary_data == true
^^^^^^^^^^^^^^^^^^^
# ./lib/bandwidth-sdk/api_client.rb:231:in `deserialize'
# ./lib/bandwidth-sdk/api_client.rb:79:in `call_api'
# ./lib/bandwidth-sdk/api/media_api.rb:153:in `get_media_with_http_info'
# ./spec/integration/media_api_integration_spec.rb:51:in `block (3 levels) in <top (required)>'
When attempting to modify the config
Bandwidth.configure do |config|
config.username = BW_USERNAME
config.password = BW_PASSWORD
config.return_binary_data = true
end
Failure/Error: config.return_binary_data = true
NoMethodError:
undefined method `return_binary_data=' for #<Bandwidth::Configuration:0x0000000106744a58 @scheme="http", @host="localhost", @base_path="", @server_index=0, @server_operation_index={}, @server_variables={}, @server_operation_variables={}, @api_key={}, @api_key_prefix={}, @client_side_validation=true, @ssl_verify=true, @ssl_verify_mode=nil, @ssl_ca_file=nil, @ssl_client_cert=nil, @ssl_client_key=nil, @middlewares={}, @timeout=60, @return_binary_data=false, @params_encoder=nil, @debugging=false, @inject_format=false, @force_ending_format=false, @logger=#<Logger:0x00000001067440a8 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x00000001068a7f80 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00000001068a7da0 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @binmode=false, @mon_data=#<Monitor:0x00000001068a7cd8>, @mon_data_owner_object_id=4660>>, @username="***", @password="***">
config.return_binary_data = true
^^^^^^^^^^^^^^^^^^^^^
# ./spec/integration/media_api_integration_spec.rb:10:in `block (3 levels) in <top (required)>'
# ./lib/bandwidth-sdk.rb:128:in `configure'
# ./spec/integration/media_api_integration_spec.rb:7:in `block (2 levels) in <top (required)>'
openapi-generator version
openapi-generator-cli 6.3.0 This has been tested on 6.5.0-SNAPSHOT as well
OpenAPI declaration file content or url
https://github.com/Bandwidth/api-specs/blob/main/bandwidth.yml
Generation Details
Client generated using the bandwidth.yml
linked above and the config file here
Steps to reproduce
After generating the client, attempting to configure the client using the snippet below should cause the error.
Bandwidth.configure do |config|
config.return_binary_data = true
end
Related issues/PRs
No open issues for this, I plan on opening a PR shortly to fix.
Suggest a fix
It seems that this issue is caused by ruby's private instance variables. Adding an attr_accessor
for return_binary_data
fixed this in my local copy of the sdk; I plan on replicating this in a PR.