[ci][test] Fix samples (#7509)

This commit is contained in:
Jim Schubert
2020-09-24 23:42:04 -04:00
committed by GitHub
parent 5f3d974a08
commit f3fbc7d782
3 changed files with 37 additions and 8 deletions

View File

@@ -64,6 +64,7 @@ module Petstore
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,
@@ -124,6 +125,7 @@ module Petstore
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,

View File

@@ -86,7 +86,7 @@ module Petstore
# @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] || {})
@@ -287,10 +287,10 @@ module Petstore
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.

View File

@@ -21,6 +21,18 @@ module Petstore
# 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)
@@ -129,6 +141,10 @@ module Petstore
@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
@@ -171,8 +187,12 @@ module Petstore
@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).
@@ -206,12 +226,17 @@ module Petstore
]
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)
@@ -221,10 +246,12 @@ module Petstore
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]}."