Skip to content

Commit

Permalink
Adds 'params_encoder' config option for Ruby clients using Faraday
Browse files Browse the repository at this point in the history
The partial templates were renamed because they no longer hold tls
settings exclusively.

fixes: OpenAPITools#9838
  • Loading branch information
dkliban committed Apr 5, 2022
1 parent 1b57024 commit 48022bc
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
: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.proxy = config.proxy if config.proxy
request_options = {
:params_encoder => @config.params_encoder
}
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options, :request => request_options) do |conn|
conn.request(:basic_auth, config.username, config.password)
@config.configure_middleware(conn)
if opts[:header_params]["Content-Type"] == "multipart/form-data"
Expand Down Expand Up @@ -84,7 +85,7 @@
request.body = req_body

# Overload default options only if provided
request.options.params_encoding = @config.params_encoding if @config.params_encoding
request.options.params_encoder = @config.params_encoder if @config.params_encoder
request.options.timeout = @config.timeout if @config.timeout
request.options.verbose = @config.debugging if @config.debugging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,11 @@ module {{moduleName}}
attr_accessor :client_side_validation

{{^isFaraday}}
{{> configuration_tls_typhoeus_partial}}
{{> configuration_typhoeus_partial}}
{{/isFaraday}}
{{#isFaraday}}
{{> configuration_tls_faraday_partial}}
{{> configuration_faraday_partial}}
{{/isFaraday}}
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
# Default to nil.
#
# @see The params_encoding option of Ethon. Related source code:
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding

attr_accessor :inject_format

Expand Down Expand Up @@ -123,14 +117,15 @@ module {{moduleName}}
@timeout = 60
# return data as binary instead of file
@return_binary_data = false
@params_encoder = nil
{{/isFaraday}}
{{^isFaraday}}
@verify_ssl = true
@verify_ssl_host = true
@params_encoding = nil
@cert_file = nil
@key_file = nil
@timeout = 0
@params_encoding = nil
{{/isFaraday}}
@debugging = false
@inject_format = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@
### Proxy setting
# HTTP Proxy settings
attr_accessor :proxy

# Set this to customize parameters encoder of array parameter.
# Default to nil. Faraday uses NestedParamsEncoder when nil.
#
# @see The params_encoder option of Faraday. Related source code:
# https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
attr_accessor :params_encoder
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@
### TLS/SSL setting
# Client private key file (for client certificate)
attr_accessor :key_file

# Set this to customize parameters encoding of array parameter with multi collectionFormat.
# Default to nil.
#
# @see The params_encoding option of Ethon. Related source code:
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def call_api(http_method, path, opts = {})
: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.proxy = config.proxy if config.proxy
request_options = {
:params_encoder => @config.params_encoder
}
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options, :request => request_options) do |conn|
conn.request(:basic_auth, config.username, config.password)
@config.configure_middleware(conn)
if opts[:header_params]["Content-Type"] == "multipart/form-data"
Expand Down Expand Up @@ -128,7 +129,7 @@ def build_request(http_method, path, request, opts = {})
request.body = req_body

# Overload default options only if provided
request.options.params_encoding = @config.params_encoding if @config.params_encoding
request.options.params_encoder = @config.params_encoder if @config.params_encoder
request.options.timeout = @config.timeout if @config.timeout
request.options.verbose = @config.debugging if @config.debugging

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ class Configuration
# HTTP Proxy settings
attr_accessor :proxy

# Set this to customize parameters encoding of array parameter with multi collectionFormat.
# Default to nil.
# Set this to customize parameters encoder of array parameter.
# Default to nil. Faraday uses NestedParamsEncoder when nil.
#
# @see The params_encoding option of Ethon. Related source code:
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding
# @see The params_encoder option of Faraday. Related source code:
# https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
attr_accessor :params_encoder


attr_accessor :inject_format

Expand Down Expand Up @@ -158,6 +159,7 @@ def initialize
@timeout = 60
# return data as binary instead of file
@return_binary_data = false
@params_encoder = nil
@debugging = false
@inject_format = false
@force_ending_format = false
Expand Down
3 changes: 2 additions & 1 deletion samples/client/petstore/ruby/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Configuration
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding


attr_accessor :inject_format

attr_accessor :force_ending_format
Expand All @@ -150,10 +151,10 @@ def initialize
@client_side_validation = true
@verify_ssl = true
@verify_ssl_host = true
@params_encoding = nil
@cert_file = nil
@key_file = nil
@timeout = 0
@params_encoding = nil
@debugging = false
@inject_format = false
@force_ending_format = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Configuration
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding


attr_accessor :inject_format

attr_accessor :force_ending_format
Expand All @@ -150,10 +151,10 @@ def initialize
@client_side_validation = true
@verify_ssl = true
@verify_ssl_host = true
@params_encoding = nil
@cert_file = nil
@key_file = nil
@timeout = 0
@params_encoding = nil
@debugging = false
@inject_format = false
@force_ending_format = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Configuration
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding


attr_accessor :inject_format

attr_accessor :force_ending_format
Expand All @@ -150,10 +151,10 @@ def initialize
@client_side_validation = true
@verify_ssl = true
@verify_ssl_host = true
@params_encoding = nil
@cert_file = nil
@key_file = nil
@timeout = 0
@params_encoding = nil
@debugging = false
@inject_format = false
@force_ending_format = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class Configuration
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding


attr_accessor :inject_format

attr_accessor :force_ending_format
Expand All @@ -150,10 +151,10 @@ def initialize
@client_side_validation = true
@verify_ssl = true
@verify_ssl_host = true
@params_encoding = nil
@cert_file = nil
@key_file = nil
@timeout = 0
@params_encoding = nil
@debugging = false
@inject_format = false
@force_ending_format = false
Expand Down

0 comments on commit 48022bc

Please sign in to comment.