diff --git a/CI/circle_parallel.sh b/CI/circle_parallel.sh index 2ff3aa6b27f..9be0f79cf9c 100755 --- a/CI/circle_parallel.sh +++ b/CI/circle_parallel.sh @@ -13,7 +13,7 @@ if [ "$NODE_INDEX" = "1" ]; then echo "Running node $NODE_INDEX ..." java -version - sudo apt-get -y install cpanminus + sudo apt-get -y install cpanminus libmagic-dev (cd samples/client/petstore/perl && /bin/bash ./test.bash) (cd samples/client/petstore/ruby && mvn integration-test) 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 fef2e864c94..19eb7c5cea9 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 @@ -13,6 +13,7 @@ require 'typhoeus' {{#isFaraday}} require 'faraday' require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') +require 'filemagic' {{/isFaraday}} {{#isHttpx}} require 'httpx' 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 3392e91033d..78452bff0d1 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 @@ -94,8 +94,8 @@ form_params.each do |key, value| case value when ::File, ::Tempfile - # TODO hardcode to application/octet-stream, need better way to detect content type - data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path) + filemagic = FileMagic.new(FileMagic::MAGIC_MIME) + data[key] = Faraday::FilePart.new(value.path, filemagic.file(value.path, true)) when ::Array, nil # let Faraday handle Array and nil parameters data[key] = value diff --git a/modules/openapi-generator/src/main/resources/ruby-client/gemspec.mustache b/modules/openapi-generator/src/main/resources/ruby-client/gemspec.mustache index 3e4b613face..b17dce7dc53 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/gemspec.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/gemspec.mustache @@ -23,6 +23,7 @@ Gem::Specification.new do |s| {{#isFaraday}} s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0' s.add_runtime_dependency 'faraday-multipart' + s.add_runtime_dependency 'ruby-filemagic' {{/isFaraday}} {{#isTyphoeus}} s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1' diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/api_client.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/api_client.rb index e1b12b0882d..74938757638 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/api_client.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/api_client.rb @@ -17,6 +17,7 @@ require 'tempfile' require 'time' require 'faraday' require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') +require 'filemagic' module OpenapiClient @@ -140,8 +141,8 @@ module OpenapiClient form_params.each do |key, value| case value when ::File, ::Tempfile - # TODO hardcode to application/octet-stream, need better way to detect content type - data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path) + filemagic = FileMagic.new(FileMagic::MAGIC_MIME) + data[key] = Faraday::FilePart.new(value.path, filemagic.file(value.path, true)) when ::Array, nil # let Faraday handle Array and nil parameters data[key] = value diff --git a/samples/client/echo_api/ruby-faraday/openapi_client.gemspec b/samples/client/echo_api/ruby-faraday/openapi_client.gemspec index 9eaf40366c8..8f99be01f0a 100644 --- a/samples/client/echo_api/ruby-faraday/openapi_client.gemspec +++ b/samples/client/echo_api/ruby-faraday/openapi_client.gemspec @@ -30,6 +30,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0' s.add_runtime_dependency 'faraday-multipart' + s.add_runtime_dependency 'ruby-filemagic' s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' 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 59b73ef4c76..89b4fc332e9 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb @@ -17,6 +17,7 @@ require 'tempfile' require 'time' require 'faraday' require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') +require 'filemagic' module Petstore @@ -140,8 +141,8 @@ module Petstore form_params.each do |key, value| case value when ::File, ::Tempfile - # TODO hardcode to application/octet-stream, need better way to detect content type - data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path) + filemagic = FileMagic.new(FileMagic::MAGIC_MIME) + data[key] = Faraday::FilePart.new(value.path, filemagic.file(value.path, true)) when ::Array, nil # let Faraday handle Array and nil parameters data[key] = value diff --git a/samples/client/petstore/ruby-faraday/petstore.gemspec b/samples/client/petstore/ruby-faraday/petstore.gemspec index 809f021a710..c9feadd2033 100644 --- a/samples/client/petstore/ruby-faraday/petstore.gemspec +++ b/samples/client/petstore/ruby-faraday/petstore.gemspec @@ -30,6 +30,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0' s.add_runtime_dependency 'faraday-multipart' + s.add_runtime_dependency 'ruby-filemagic' s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'