Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ruby] Add Flag to Allow Ignoring Operation Servers #18934

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ module {{moduleName}}
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -146,6 +154,7 @@ module {{moduleName}}
@configure_session_blocks = []
{{/isHttpx}}
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -180,6 +189,7 @@ module {{moduleName}}

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -170,6 +178,7 @@ def initialize
@return_binary_data = false
@params_encoder = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -204,6 +213,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -134,6 +142,7 @@ def initialize
@timeout = 60
@configure_session_blocks = []
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -168,6 +177,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -166,6 +174,7 @@ def initialize
@timeout = 0
@params_encoding = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -200,6 +209,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -166,6 +174,7 @@ def initialize
@timeout = 0
@params_encoding = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -200,6 +209,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
10 changes: 10 additions & 0 deletions samples/client/petstore/ruby-faraday/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -170,6 +178,7 @@ def initialize
@return_binary_data = false
@params_encoder = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -204,6 +213,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
expect(config.base_url).to eq('https://localhost:8080/v2')
end

it 'ignores the operation server settings and uses the custom base url' do
config.scheme = 'https'
config.host = 'api.example.com'
config.base_path = '/v2'
config.ignore_operation_servers = true
expect(config.base_url).to eq('https://api.example.com/v2')
expect(config.base_url(:'PetApi.add_pet')).to eq('https://api.example.com/v2')
end

it 'throws argument error when attempting to use a server index that is out of bounds' do
config.server_operation_index = {
:'PetApi.add_pet' => 10
Expand Down
10 changes: 10 additions & 0 deletions samples/client/petstore/ruby-httpx/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -134,6 +142,7 @@ def initialize
@timeout = 60
@configure_session_blocks = []
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -168,6 +177,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
10 changes: 10 additions & 0 deletions samples/client/petstore/ruby/lib/petstore/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -166,6 +174,7 @@ def initialize
@timeout = 0
@params_encoding = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -200,6 +209,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
expect(config.base_url).to eq('https://localhost:8080/v2')
end

it 'ignores the operation server settings and uses the custom base url' do
config.scheme = 'https'
config.host = 'api.example.com'
config.base_path = '/v2'
config.ignore_operation_servers = true
expect(config.base_url).to eq('https://api.example.com/v2')
expect(config.base_url(:'PetApi.add_pet')).to eq('https://api.example.com/v2')
end

it 'throws argument error when attempting to use a server index that is out of bounds' do
config.server_operation_index = {
:'PetApi.add_pet' => 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -166,6 +174,7 @@ def initialize
@timeout = 0
@params_encoding = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -200,6 +209,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -166,6 +174,7 @@ def initialize
@timeout = 0
@params_encoding = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -200,6 +209,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ class Configuration
# @return [true, false]
attr_accessor :debugging

# Set this to ignore operation servers for the API client. This is useful when you need to
# send requests to a different server than the one specified in the OpenAPI document.
# Will default to the base url defined in the spec but can be overridden by setting
# `scheme`, `host`, `base_path` directly.
# Default to false.
# @return [true, false]
attr_accessor :ignore_operation_servers

# Defines the logger used for debugging.
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
#
Expand Down Expand Up @@ -166,6 +174,7 @@ def initialize
@timeout = 0
@params_encoding = nil
@debugging = false
@ignore_operation_servers = false
@inject_format = false
@force_ending_format = false
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
Expand Down Expand Up @@ -200,6 +209,7 @@ def base_path=(base_path)

# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
if operation_server_settings.key?(operation) then
index = server_operation_index.fetch(operation, server_index)
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
Expand Down
Loading