Skip to content

Commit

Permalink
[ci][test] Fix samples (OpenAPITools#7509)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimschubert authored Sep 25, 2020
1 parent 5f3d974 commit f3fbc7d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def array_with_http_info(opts = {})
auth_names = opts[:debug_auth_names] || []

new_options = opts.merge(
:operation => :"UsageApi.array",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
Expand Down Expand Up @@ -124,6 +125,7 @@ def map_with_http_info(opts = {})
auth_names = opts[:debug_auth_names] || []

new_options = opts.merge(
:operation => :"UsageApi.map",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def call_api(http_method, path, opts = {})
# @option opts [Object] :body HTTP body (JSON/XML)
# @return [Typhoeus::Request] A Typhoeus Request
def build_request(http_method, path, opts = {})
url = build_request_url(path)
url = build_request_url(path, opts)
http_method = http_method.to_sym.downcase

header_params = @default_headers.merge(opts[:header_params] || {})
Expand Down Expand Up @@ -287,10 +287,10 @@ def sanitize_filename(filename)
filename.gsub(/.*[\/\\]/, '')
end

def build_request_url(path)
def build_request_url(path, opts = {})
# Add leading and trailing slashes to path
path = "/#{path}".gsub(/\/+/, '/')
@config.base_url + path
@config.base_url(opts[:operation]) + path
end

# Update hearder and query params based on authentication settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class Configuration
# Defines url base path
attr_accessor :base_path

# Define server configuration index
attr_accessor :server_index

# Define server operation configuration index
attr_accessor :server_operation_index

# Default server variables
attr_accessor :server_variables

# Default server operation variables
attr_accessor :server_operation_variables

# Defines API keys used with API Key authentications.
#
# @return [Hash] key: parameter name, value: parameter value (API key)
Expand Down Expand Up @@ -129,6 +141,10 @@ def initialize
@scheme = 'http'
@host = 'petstore.swagger.io:-1'
@base_path = '/v2'
@server_index = 0
@server_operation_index = {}
@server_variables = {}
@server_operation_variables = {}
@api_key = {}
@api_key_prefix = {}
@timeout = 0
Expand Down Expand Up @@ -171,8 +187,12 @@ def base_path=(base_path)
@base_path = '' if @base_path == '/'
end

def base_url
"#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
# Returns base URL for specified operation based on server settings
def base_url(operation = nil)
index = server_operation_index.fetch(operation, server_index)
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil

server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
end

# Gets API key (with prefix if set).
Expand Down Expand Up @@ -206,12 +226,17 @@ def server_settings
]
end

def operation_server_settings
{
}
end

# Returns URL based on server settings
#
# @param index array index of the server settings
# @param variables hash of variable and the corresponding value
def server_url(index, variables = {})
servers = server_settings
def server_url(index, variables = {}, servers = nil)
servers = server_settings if servers == nil

# check array index out of bound
if (index < 0 || index >= servers.size)
Expand All @@ -221,10 +246,12 @@ def server_url(index, variables = {})
server = servers[index]
url = server[:url]

return url unless server.key? :variables

# go through variable and assign a value
server[:variables].each do |name, variable|
if variables.key?(name)
if (server[:variables][name][:enum_values].include? variables[name])
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
url.gsub! "{" + name.to_s + "}", variables[name]
else
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
Expand Down

0 comments on commit f3fbc7d

Please sign in to comment.