diff --git a/modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache b/modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache index 7e0568b95d79..a661cd00b38d 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache @@ -91,6 +91,12 @@ module {{moduleName}} end {{/isFaraday}} + # return byte stream for Binary return type + if return_type == 'Binary' + encoding = body.encoding + return @stream.join.force_encoding(encoding) + end + return nil if body.nil? || body.empty? # return response body directly for String return type diff --git a/modules/openapi-generator/src/main/resources/ruby-client/api_client_faraday_partial.mustache b/modules/openapi-generator/src/main/resources/ruby-client/api_client_faraday_partial.mustache index 4eed519e144a..8a79f43a6ede 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/api_client_faraday_partial.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/api_client_faraday_partial.mustache @@ -90,7 +90,7 @@ request.url url request.params = query_params - download_file(request) if opts[:return_type] == 'File' + download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary' request end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb b/samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb index 55a4331dd0df..f85205825043 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb @@ -134,7 +134,7 @@ def build_request(http_method, path, request, opts = {}) request.url url request.params = query_params - download_file(request) if opts[:return_type] == 'File' + download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary' request end @@ -220,6 +220,12 @@ def deserialize(response, return_type) return @tempfile end + # return byte stream for Binary return type + if return_type == 'Binary' + encoding = body.encoding + return @stream.join.force_encoding(encoding) + end + return nil if body.nil? || body.empty? # return response body directly for String return type diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index 382754288f7e..804cdc24cb56 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -217,6 +217,12 @@ def deserialize(response, return_type) # note that response body is empty when the file is written in chunks in request on_body callback return @tempfile if return_type == 'File' + # return byte stream for Binary return type + if return_type == 'Binary' + encoding = body.encoding + return @stream.join.force_encoding(encoding) + end + return nil if body.nil? || body.empty? # return response body directly for String return type diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb b/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb index 39b60ce5a00a..5ec9b8d6dc98 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb +++ b/samples/openapi3/client/extensions/x-auth-id-alias/ruby-client/lib/x_auth_id_alias/api_client.rb @@ -217,6 +217,12 @@ def deserialize(response, return_type) # note that response body is empty when the file is written in chunks in request on_body callback return @tempfile if return_type == 'File' + # return byte stream for Binary return type + if return_type == 'Binary' + encoding = body.encoding + return @stream.join.force_encoding(encoding) + end + return nil if body.nil? || body.empty? # return response body directly for String return type diff --git a/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb b/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb index e961dfec106a..7497c3c60f76 100644 --- a/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb +++ b/samples/openapi3/client/features/dynamic-servers/ruby/lib/dynamic_servers/api_client.rb @@ -216,6 +216,12 @@ def deserialize(response, return_type) # note that response body is empty when the file is written in chunks in request on_body callback return @tempfile if return_type == 'File' + # return byte stream for Binary return type + if return_type == 'Binary' + encoding = body.encoding + return @stream.join.force_encoding(encoding) + end + return nil if body.nil? || body.empty? # return response body directly for String return type diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb index ebabf150bf47..9757a43b4f98 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb @@ -216,6 +216,12 @@ def deserialize(response, return_type) # note that response body is empty when the file is written in chunks in request on_body callback return @tempfile if return_type == 'File' + # return byte stream for Binary return type + if return_type == 'Binary' + encoding = body.encoding + return @stream.join.force_encoding(encoding) + end + return nil if body.nil? || body.empty? # return response body directly for String return type