diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache index 837b1234fd0..54854efe332 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache @@ -71,6 +71,7 @@ module {{moduleName}} :method => http_method, :headers => header_params, :params => query_params, + :timeout => @config.timeout, :ssl_verifypeer => @config.verify_ssl, :sslcert => @config.cert_file, :sslkey => @config.key_file, diff --git a/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache b/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache index 4c05f2560fa..160fa85a57d 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/configuration.mustache @@ -60,6 +60,10 @@ module {{moduleName}} # @return [String] attr_accessor :temp_folder_path + # The time limit for HTTP request in seconds. + # Default to 0 (never times out). + attr_accessor :timeout + ### TLS/SSL # Set this to false to skip verifying SSL certificate when calling API from https server. # Default to true. @@ -93,6 +97,7 @@ module {{moduleName}} @base_path = '{{contextPath}}' @api_key = {} @api_key_prefix = {} + @timeout = 0 @verify_ssl = true @cert_file = nil @key_file = nil diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index 52a3eb43855..53be21db3b0 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -71,6 +71,7 @@ module Petstore :method => http_method, :headers => header_params, :params => query_params, + :timeout => @config.timeout, :ssl_verifypeer => @config.verify_ssl, :sslcert => @config.cert_file, :sslkey => @config.key_file, diff --git a/samples/client/petstore/ruby/lib/petstore/configuration.rb b/samples/client/petstore/ruby/lib/petstore/configuration.rb index 7173a4450c6..0a67bae014f 100644 --- a/samples/client/petstore/ruby/lib/petstore/configuration.rb +++ b/samples/client/petstore/ruby/lib/petstore/configuration.rb @@ -60,6 +60,10 @@ module Petstore # @return [String] attr_accessor :temp_folder_path + # The time limit for HTTP request in seconds. + # Default to 0 (never times out). + attr_accessor :timeout + ### TLS/SSL # Set this to false to skip verifying SSL certificate when calling API from https server. # Default to true. @@ -93,6 +97,7 @@ module Petstore @base_path = '/v2' @api_key = {} @api_key_prefix = {} + @timeout = 0 @verify_ssl = true @cert_file = nil @key_file = nil diff --git a/samples/client/petstore/ruby/spec/api_client_spec.rb b/samples/client/petstore/ruby/spec/api_client_spec.rb index c2bfef4e8e4..aeb4eefad51 100644 --- a/samples/client/petstore/ruby/spec/api_client_spec.rb +++ b/samples/client/petstore/ruby/spec/api_client_spec.rb @@ -59,7 +59,7 @@ describe Petstore::ApiClient do c.api_key['api_key'] = 'special-key2' end api_client2 = Petstore::ApiClient.new(config2) - + auth_names = ['api_key', 'unknown'] header_params = {} @@ -82,7 +82,7 @@ describe Petstore::ApiClient do end api_client = Petstore::ApiClient.new - + header_params = {} query_params = {} auth_names = ['api_key', 'unknown'] @@ -92,6 +92,25 @@ describe Petstore::ApiClient do end end + describe "timeout in #build_request" do + let(:config) { Petstore::Configuration.new } + let(:api_client) { Petstore::ApiClient.new(config) } + + it "defaults to 0" do + Petstore::Configuration.default.timeout.should == 0 + config.timeout.should == 0 + + request = api_client.build_request(:get, '/test') + request.options[:timeout].should == 0 + end + + it "can be customized" do + config.timeout = 100 + request = api_client.build_request(:get, '/test') + request.options[:timeout].should == 100 + end + end + describe "#deserialize" do it "handles Hash" do api_client = Petstore::ApiClient.new