Adds 'params_encoder' config option for Ruby clients using Faraday (#9839)

The partial templates were renamed because they no longer hold tls
settings exclusively.

fixes: #9838
This commit is contained in:
Dennis Kliban 2022-04-08 22:14:38 -04:00 committed by GitHub
parent cd56a4b1a1
commit e783e9b780
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 43 additions and 26 deletions

View File

@ -10,9 +10,10 @@
:client_cert => @config.ssl_client_cert, :client_cert => @config.ssl_client_cert,
:client_key => @config.ssl_client_key :client_key => @config.ssl_client_key
} }
request_options = {
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn| :params_encoder => @config.params_encoder
conn.proxy = config.proxy if config.proxy }
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options, :request => request_options) do |conn|
conn.request(:basic_auth, config.username, config.password) conn.request(:basic_auth, config.username, config.password)
@config.configure_middleware(conn) @config.configure_middleware(conn)
if opts[:header_params]["Content-Type"] == "multipart/form-data" if opts[:header_params]["Content-Type"] == "multipart/form-data"
@ -84,7 +85,7 @@
request.body = req_body request.body = req_body
# Overload default options only if provided # 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.timeout = @config.timeout if @config.timeout
request.options.verbose = @config.debugging if @config.debugging request.options.verbose = @config.debugging if @config.debugging

View File

@ -84,17 +84,11 @@ module {{moduleName}}
attr_accessor :client_side_validation attr_accessor :client_side_validation
{{^isFaraday}} {{^isFaraday}}
{{> configuration_tls_typhoeus_partial}} {{> configuration_typhoeus_partial}}
{{/isFaraday}} {{/isFaraday}}
{{#isFaraday}} {{#isFaraday}}
{{> configuration_tls_faraday_partial}} {{> configuration_faraday_partial}}
{{/isFaraday}} {{/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 attr_accessor :inject_format
@ -123,14 +117,15 @@ module {{moduleName}}
@timeout = 60 @timeout = 60
# return data as binary instead of file # return data as binary instead of file
@return_binary_data = false @return_binary_data = false
@params_encoder = nil
{{/isFaraday}} {{/isFaraday}}
{{^isFaraday}} {{^isFaraday}}
@verify_ssl = true @verify_ssl = true
@verify_ssl_host = true @verify_ssl_host = true
@params_encoding = nil
@cert_file = nil @cert_file = nil
@key_file = nil @key_file = nil
@timeout = 0 @timeout = 0
@params_encoding = nil
{{/isFaraday}} {{/isFaraday}}
@debugging = false @debugging = false
@inject_format = false @inject_format = false

View File

@ -31,3 +31,10 @@
### Proxy setting ### Proxy setting
# HTTP Proxy settings # HTTP Proxy settings
attr_accessor :proxy 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

View File

@ -32,3 +32,10 @@
### TLS/SSL setting ### TLS/SSL setting
# Client private key file (for client certificate) # Client private key file (for client certificate)
attr_accessor :key_file 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

View File

@ -54,9 +54,10 @@ module Petstore
:client_cert => @config.ssl_client_cert, :client_cert => @config.ssl_client_cert,
:client_key => @config.ssl_client_key :client_key => @config.ssl_client_key
} }
request_options = {
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn| :params_encoder => @config.params_encoder
conn.proxy = config.proxy if config.proxy }
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options, :request => request_options) do |conn|
conn.request(:basic_auth, config.username, config.password) conn.request(:basic_auth, config.username, config.password)
@config.configure_middleware(conn) @config.configure_middleware(conn)
if opts[:header_params]["Content-Type"] == "multipart/form-data" if opts[:header_params]["Content-Type"] == "multipart/form-data"
@ -128,7 +129,7 @@ module Petstore
request.body = req_body request.body = req_body
# Overload default options only if provided # 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.timeout = @config.timeout if @config.timeout
request.options.verbose = @config.debugging if @config.debugging request.options.verbose = @config.debugging if @config.debugging

View File

@ -125,12 +125,13 @@ module Petstore
# HTTP Proxy settings # HTTP Proxy settings
attr_accessor :proxy attr_accessor :proxy
# Set this to customize parameters encoding of array parameter with multi collectionFormat. # Set this to customize parameters encoder of array parameter.
# Default to nil. # Default to nil. Faraday uses NestedParamsEncoder when nil.
# #
# @see The params_encoding option of Ethon. Related source code: # @see The params_encoder option of Faraday. Related source code:
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
attr_accessor :params_encoding attr_accessor :params_encoder
attr_accessor :inject_format attr_accessor :inject_format
@ -158,6 +159,7 @@ module Petstore
@timeout = 60 @timeout = 60
# return data as binary instead of file # return data as binary instead of file
@return_binary_data = false @return_binary_data = false
@params_encoder = nil
@debugging = false @debugging = false
@inject_format = false @inject_format = false
@force_ending_format = false @force_ending_format = false

View File

@ -133,6 +133,7 @@ module Petstore
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding attr_accessor :params_encoding
attr_accessor :inject_format attr_accessor :inject_format
attr_accessor :force_ending_format attr_accessor :force_ending_format
@ -150,10 +151,10 @@ module Petstore
@client_side_validation = true @client_side_validation = true
@verify_ssl = true @verify_ssl = true
@verify_ssl_host = true @verify_ssl_host = true
@params_encoding = nil
@cert_file = nil @cert_file = nil
@key_file = nil @key_file = nil
@timeout = 0 @timeout = 0
@params_encoding = nil
@debugging = false @debugging = false
@inject_format = false @inject_format = false
@force_ending_format = false @force_ending_format = false

View File

@ -133,6 +133,7 @@ module XAuthIDAlias
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding attr_accessor :params_encoding
attr_accessor :inject_format attr_accessor :inject_format
attr_accessor :force_ending_format attr_accessor :force_ending_format
@ -150,10 +151,10 @@ module XAuthIDAlias
@client_side_validation = true @client_side_validation = true
@verify_ssl = true @verify_ssl = true
@verify_ssl_host = true @verify_ssl_host = true
@params_encoding = nil
@cert_file = nil @cert_file = nil
@key_file = nil @key_file = nil
@timeout = 0 @timeout = 0
@params_encoding = nil
@debugging = false @debugging = false
@inject_format = false @inject_format = false
@force_ending_format = false @force_ending_format = false

View File

@ -133,6 +133,7 @@ module DynamicServers
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding attr_accessor :params_encoding
attr_accessor :inject_format attr_accessor :inject_format
attr_accessor :force_ending_format attr_accessor :force_ending_format
@ -150,10 +151,10 @@ module DynamicServers
@client_side_validation = true @client_side_validation = true
@verify_ssl = true @verify_ssl = true
@verify_ssl_host = true @verify_ssl_host = true
@params_encoding = nil
@cert_file = nil @cert_file = nil
@key_file = nil @key_file = nil
@timeout = 0 @timeout = 0
@params_encoding = nil
@debugging = false @debugging = false
@inject_format = false @inject_format = false
@force_ending_format = false @force_ending_format = false

View File

@ -133,6 +133,7 @@ module Petstore
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96 # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
attr_accessor :params_encoding attr_accessor :params_encoding
attr_accessor :inject_format attr_accessor :inject_format
attr_accessor :force_ending_format attr_accessor :force_ending_format
@ -150,10 +151,10 @@ module Petstore
@client_side_validation = true @client_side_validation = true
@verify_ssl = true @verify_ssl = true
@verify_ssl_host = true @verify_ssl_host = true
@params_encoding = nil
@cert_file = nil @cert_file = nil
@key_file = nil @key_file = nil
@timeout = 0 @timeout = 0
@params_encoding = nil
@debugging = false @debugging = false
@inject_format = false @inject_format = false
@force_ending_format = false @force_ending_format = false