diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java index 2f2af730e38..0b1b59b98df 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java @@ -233,14 +233,14 @@ public class RubyClientCodegen extends AbstractRubyCodegen { supportingFiles.add(new SupportingFile("rubocop.mustache", "", ".rubocop.yml")); supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml")); supportingFiles.add(new SupportingFile("gemspec.mustache", "", gemName + ".gemspec")); + supportingFiles.add(new SupportingFile("configuration.mustache", gemFolder, "configuration.rb")); if (TYPHOEUS.equals(getLibrary())) { supportingFiles.add(new SupportingFile("api_client.mustache", gemFolder, "api_client.rb")); - supportingFiles.add(new SupportingFile("configuration.mustache", gemFolder, "configuration.rb")); supportingFiles.add(new SupportingFile("Gemfile.lock.mustache", "", "Gemfile.lock")); } else if (FARADAY.equals(getLibrary())) { supportingFiles.add(new SupportingFile("faraday_api_client.mustache", gemFolder, "api_client.rb")); - supportingFiles.add(new SupportingFile("faraday_configuration.mustache", gemFolder, "configuration.rb")); + additionalProperties.put("isFaraday", Boolean.TRUE); } else { throw new RuntimeException("Invalid HTTP library " + getLibrary() + ". Only faraday, typhoeus are supported."); } diff --git a/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache b/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache index 3c0148fbd4d..72f6fe90e28 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/configuration.mustache @@ -71,41 +71,12 @@ module {{moduleName}} # @return [true, false] attr_accessor :client_side_validation - ### TLS/SSL setting - # Set this to false to skip verifying SSL certificate when calling API from https server. - # Default to true. - # - # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. - # - # @return [true, false] - attr_accessor :verify_ssl - - ### TLS/SSL setting - # Set this to false to skip verifying SSL host name - # Default to true. - # - # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. - # - # @return [true, false] - attr_accessor :verify_ssl_host - - ### TLS/SSL setting - # Set this to customize the certificate file to verify the peer. - # - # @return [String] the path to the certificate file - # - # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: - # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 - attr_accessor :ssl_ca_cert - - ### TLS/SSL setting - # Client certificate file (for client certificate) - attr_accessor :cert_file - - ### TLS/SSL setting - # Client private key file (for client certificate) - attr_accessor :key_file - +{{^isFaraday}} +{{> configuration_tls_typhoeus_partial}} +{{/isFaraday}} +{{#isFaraday}} +{{> configuration_tls_faraday_partial}} +{{/isFaraday}} # Set this to customize parameters encoding of array parameter with multi collectionFormat. # Default to nil. # @@ -125,11 +96,20 @@ module {{moduleName}} @api_key_prefix = {} @timeout = 0 @client_side_validation = true + {{#isFaraday}} + @ssl_verify = true + @ssl_verify_mode = nil + @ssl_ca_file = nil + @ssl_client_cert = nil + @ssl_client_key = nil + {{/isFaraday}} + {{^isFaraday}} @verify_ssl = true @verify_ssl_host = true @params_encoding = nil @cert_file = nil @key_file = nil + {{/isFaraday}} @debugging = false @inject_format = false @force_ending_format = false diff --git a/modules/openapi-generator/src/main/resources/ruby-client/configuration_tls_faraday_partial.mustache b/modules/openapi-generator/src/main/resources/ruby-client/configuration_tls_faraday_partial.mustache new file mode 100644 index 00000000000..e5f4085cda2 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ruby-client/configuration_tls_faraday_partial.mustache @@ -0,0 +1,29 @@ + ### TLS/SSL setting + # Set this to false to skip verifying SSL certificate when calling API from https server. + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :ssl_verify + + ### TLS/SSL setting + # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html) + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + attr_accessor :ssl_verify_mode + + ### TLS/SSL setting + # Set this to customize the certificate file to verify the peer. + # + # @return [String] the path to the certificate file + attr_accessor :ssl_ca_file + + ### TLS/SSL setting + # Client certificate file (for client certificate) + attr_accessor :ssl_client_cert + + ### TLS/SSL setting + # Client private key file (for client certificate) + attr_accessor :ssl_client_key diff --git a/modules/openapi-generator/src/main/resources/ruby-client/configuration_tls_typhoeus_partial.mustache b/modules/openapi-generator/src/main/resources/ruby-client/configuration_tls_typhoeus_partial.mustache new file mode 100644 index 00000000000..b75954c254a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ruby-client/configuration_tls_typhoeus_partial.mustache @@ -0,0 +1,34 @@ + ### TLS/SSL setting + # Set this to false to skip verifying SSL certificate when calling API from https server. + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl + + ### TLS/SSL setting + # Set this to false to skip verifying SSL host name + # Default to true. + # + # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. + # + # @return [true, false] + attr_accessor :verify_ssl_host + + ### TLS/SSL setting + # Set this to customize the certificate file to verify the peer. + # + # @return [String] the path to the certificate file + # + # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: + # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 + attr_accessor :ssl_ca_cert + + ### TLS/SSL setting + # Client certificate file (for client certificate) + attr_accessor :cert_file + + ### TLS/SSL setting + # Client private key file (for client certificate) + attr_accessor :key_file diff --git a/modules/openapi-generator/src/main/resources/ruby-client/faraday_api_client.mustache b/modules/openapi-generator/src/main/resources/ruby-client/faraday_api_client.mustache index f628ffecf07..14509b18a00 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/faraday_api_client.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/faraday_api_client.mustache @@ -107,8 +107,6 @@ module {{moduleName}} update_params_for_auth! header_params, query_params, opts[:auth_names] - - req_opts = { :method => http_method, :headers => header_params, @@ -118,7 +116,6 @@ module {{moduleName}} :verbose => @config.debugging } - if [:post, :patch, :put, :delete].include?(http_method) req_body = build_request_body(header_params, form_params, opts[:body]) req_opts.update :body => req_body diff --git a/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/api_client.rb b/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/api_client.rb index f5167c18671..dba9af066bb 100644 --- a/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/api_client.rb +++ b/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/api_client.rb @@ -46,7 +46,15 @@ module Petstore # @return [Array<(Object, Integer, Hash)>] an array of 3 elements: # the data deserialized from response body (could be nil), response status code and response headers. def call_api(http_method, path, opts = {}) - connection = Faraday.new(:url => config.base_url) do |conn| + ssl_options = { + :ca_file => @config.ssl_ca_file, + :verify => @config.ssl_verify, + :verify => @config.ssl_verify_mode, + :client_cert => @config.ssl_client_cert, + :client_key => @config.ssl_client_key + } + + connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn| conn.basic_auth(config.username, config.password) if opts[:header_params]["Content-Type"] == "multipart/form-data" conn.request :multipart @@ -54,6 +62,7 @@ module Petstore end conn.adapter(Faraday.default_adapter) end + begin response = connection.public_send(http_method.to_sym.downcase) do |req| build_request(http_method, path, req, opts) @@ -106,25 +115,15 @@ module Petstore update_params_for_auth! header_params, query_params, opts[:auth_names] - # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false) - _verify_ssl_host = @config.verify_ssl_host ? 2 : 0 - req_opts = { :method => http_method, :headers => header_params, :params => query_params, :params_encoding => @config.params_encoding, :timeout => @config.timeout, - :ssl_verifypeer => @config.verify_ssl, - :ssl_verifyhost => _verify_ssl_host, - :sslcert => @config.cert_file, - :sslkey => @config.key_file, :verbose => @config.debugging } - # set custom cert, if provided - req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert - if [:post, :patch, :put, :delete].include?(http_method) req_body = build_request_body(header_params, form_params, opts[:body]) req_opts.update :body => req_body diff --git a/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/configuration.rb b/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/configuration.rb index 73a5712c90d..02264ad9516 100644 --- a/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/configuration.rb +++ b/samples/openapi3/client/petstore/ruby-faraday/lib/petstore/configuration.rb @@ -86,33 +86,28 @@ module Petstore # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. # # @return [true, false] - attr_accessor :verify_ssl + attr_accessor :ssl_verify ### TLS/SSL setting - # Set this to false to skip verifying SSL host name - # Default to true. + # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html) # # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks. # - # @return [true, false] - attr_accessor :verify_ssl_host + attr_accessor :ssl_verify_mode ### TLS/SSL setting # Set this to customize the certificate file to verify the peer. # # @return [String] the path to the certificate file - # - # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code: - # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145 - attr_accessor :ssl_ca_cert + attr_accessor :ssl_ca_file ### TLS/SSL setting # Client certificate file (for client certificate) - attr_accessor :cert_file + attr_accessor :ssl_client_cert ### TLS/SSL setting # Client private key file (for client certificate) - attr_accessor :key_file + attr_accessor :ssl_client_key # Set this to customize parameters encoding of array parameter with multi collectionFormat. # Default to nil. @@ -133,11 +128,11 @@ module Petstore @api_key_prefix = {} @timeout = 0 @client_side_validation = true - @verify_ssl = true - @verify_ssl_host = true - @params_encoding = nil - @cert_file = nil - @key_file = nil + @ssl_verify = true + @ssl_verify_mode = nil + @ssl_ca_file = nil + @ssl_client_cert = nil + @ssl_client_key = nil @debugging = false @inject_format = false @force_ending_format = false diff --git a/samples/openapi3/client/petstore/ruby-faraday/petstore.gemspec b/samples/openapi3/client/petstore/ruby-faraday/petstore.gemspec index 6cbf88ba127..c414c1806b0 100644 --- a/samples/openapi3/client/petstore/ruby-faraday/petstore.gemspec +++ b/samples/openapi3/client/petstore/ruby-faraday/petstore.gemspec @@ -33,6 +33,10 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0' s.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.1' s.add_development_dependency 'webmock', '~> 1.24', '>= 1.24.3' + s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6' + s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2' + s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16' + s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.12' s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? } s.test_files = `find spec/*`.split("\n")