diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api/usage_api.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api/usage_api.rb index a7f33e7a2ed7e7221374516d4201b53f84c493ee..8729925f0973992891a76e176e23f5c47999d56a 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api/usage_api.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api/usage_api.rb @@ -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, diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb index 228c890a379cee1434ae5d685f0b9fe21914b6ec..4afcf581df15550b8d289379528ea19f8b20f1ea 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/api_client.rb @@ -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. diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/configuration.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/configuration.rb index 85f1d940a4031857fb127a23081e1eafd732a951..bb6e151713ba07242d3a67718898423593407f13 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/configuration.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/configuration.rb @@ -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]}."