forked from loafle/openapi-generator-original
Add debugging switch to Ruby generator
This commit is contained in:
parent
b803895750
commit
229ea93627
@ -1,6 +1,3 @@
|
||||
require 'logger'
|
||||
require 'json'
|
||||
|
||||
module {{moduleName}}
|
||||
module Swagger
|
||||
class << self
|
||||
@ -25,8 +22,7 @@ module {{moduleName}}
|
||||
def configure
|
||||
yield(configuration) if block_given?
|
||||
|
||||
# Configure logger. Default to use Rails
|
||||
self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
|
||||
self.logger = configuration.logger
|
||||
|
||||
# remove :// from scheme
|
||||
configuration.scheme.sub!(/:\/\//, '')
|
||||
|
@ -1,7 +1,11 @@
|
||||
require 'logger'
|
||||
|
||||
module {{moduleName}}
|
||||
module Swagger
|
||||
class Configuration
|
||||
attr_accessor :format, :api_key, :api_key_prefix, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params, :user_agent, :verify_ssl
|
||||
attr_accessor :format, :api_key, :api_key_prefix, :username, :password, :auth_token,
|
||||
:scheme, :host, :base_path, :user_agent, :debug, :logger, :inject_format,
|
||||
:force_ending_format, :camelize_params, :user_agent, :verify_ssl
|
||||
|
||||
# Defaults go in here..
|
||||
def initialize
|
||||
@ -23,6 +27,12 @@ module {{moduleName}}
|
||||
# Note: do NOT set it to false in production code, otherwise you would
|
||||
# face multiple types of cryptographic attacks
|
||||
@verify_ssl = true
|
||||
|
||||
# whether to enable debugging
|
||||
@debug = false
|
||||
|
||||
# configure logger, default to logger of Rails (if in Rails) or STDOUT
|
||||
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -125,12 +125,17 @@ module {{moduleName}}
|
||||
data.each do |key, value|
|
||||
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
|
||||
end
|
||||
data
|
||||
elsif @body # http body is JSON
|
||||
@body.is_a?(String) ? @body : @body.to_json
|
||||
data = @body.is_a?(String) ? @body : @body.to_json
|
||||
else
|
||||
nil
|
||||
data = nil
|
||||
end
|
||||
|
||||
if Swagger.configuration.debug
|
||||
Swagger.logger.debug "HTTP request body param ~BEGIN~\n#{data}\n~END~\n"
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
# Construct a query string from the query-string-type params
|
||||
@ -159,13 +164,10 @@ module {{moduleName}}
|
||||
end
|
||||
|
||||
def make
|
||||
#TODO use configuration setting to determine if debugging
|
||||
#logger = Logger.new STDOUT
|
||||
#logger.debug self.url
|
||||
|
||||
request_options = {
|
||||
:ssl_verifypeer => Swagger.configuration.verify_ssl,
|
||||
:headers => self.headers.stringify_keys
|
||||
:headers => self.headers.stringify_keys,
|
||||
:verbose => Swagger.configuration.debug
|
||||
}
|
||||
response = case self.http_method.to_sym
|
||||
when :get,:GET
|
||||
@ -198,6 +200,11 @@ module {{moduleName}}
|
||||
request_options.merge(:body => self.outgoing_body)
|
||||
)
|
||||
end
|
||||
|
||||
if Swagger.configuration.debug
|
||||
Swagger.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
||||
end
|
||||
|
||||
Response.new(response)
|
||||
end
|
||||
|
||||
|
@ -43,9 +43,11 @@ ruby -Ilib script.rb
|
||||
require 'swagger_client'
|
||||
|
||||
SwaggerClient::Swagger.configure do |config|
|
||||
config.api_key = 'special-key'
|
||||
config.api_key['api_key'] = 'special-key'
|
||||
config.host = 'petstore.swagger.io'
|
||||
config.base_path = '/v2'
|
||||
# enable debugging (default is false)
|
||||
config.debug = true
|
||||
end
|
||||
```
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
require 'logger'
|
||||
require 'json'
|
||||
|
||||
module SwaggerClient
|
||||
module Swagger
|
||||
class << self
|
||||
@ -25,8 +22,7 @@ module SwaggerClient
|
||||
def configure
|
||||
yield(configuration) if block_given?
|
||||
|
||||
# Configure logger. Default to use Rails
|
||||
self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
|
||||
self.logger = configuration.logger
|
||||
|
||||
# remove :// from scheme
|
||||
configuration.scheme.sub!(/:\/\//, '')
|
||||
|
@ -1,7 +1,11 @@
|
||||
require 'logger'
|
||||
|
||||
module SwaggerClient
|
||||
module Swagger
|
||||
class Configuration
|
||||
attr_accessor :format, :api_key, :api_key_prefix, :username, :password, :auth_token, :scheme, :host, :base_path, :user_agent, :logger, :inject_format, :force_ending_format, :camelize_params, :user_agent, :verify_ssl
|
||||
attr_accessor :format, :api_key, :api_key_prefix, :username, :password, :auth_token,
|
||||
:scheme, :host, :base_path, :user_agent, :debug, :logger, :inject_format,
|
||||
:force_ending_format, :camelize_params, :user_agent, :verify_ssl
|
||||
|
||||
# Defaults go in here..
|
||||
def initialize
|
||||
@ -23,6 +27,12 @@ module SwaggerClient
|
||||
# Note: do NOT set it to false in production code, otherwise you would
|
||||
# face multiple types of cryptographic attacks
|
||||
@verify_ssl = true
|
||||
|
||||
# whether to enable debugging
|
||||
@debug = false
|
||||
|
||||
# configure logger, default to logger of Rails (if in Rails) or STDOUT
|
||||
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -124,12 +124,17 @@ module SwaggerClient
|
||||
data.each do |key, value|
|
||||
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
|
||||
end
|
||||
data
|
||||
elsif @body # http body is JSON
|
||||
@body.is_a?(String) ? @body : @body.to_json
|
||||
data = @body.is_a?(String) ? @body : @body.to_json
|
||||
else
|
||||
nil
|
||||
data = nil
|
||||
end
|
||||
|
||||
if Swagger.configuration.debug
|
||||
Swagger.logger.debug "HTTP request body param ~BEGIN~\n#{data}\n~END~\n"
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
|
||||
# Construct a query string from the query-string-type params
|
||||
@ -158,13 +163,10 @@ module SwaggerClient
|
||||
end
|
||||
|
||||
def make
|
||||
#TODO use configuration setting to determine if debugging
|
||||
#logger = Logger.new STDOUT
|
||||
#logger.debug self.url
|
||||
|
||||
request_options = {
|
||||
:ssl_verifypeer => Swagger.configuration.verify_ssl,
|
||||
:headers => self.headers.stringify_keys
|
||||
:headers => self.headers.stringify_keys,
|
||||
:verbose => Swagger.configuration.debug
|
||||
}
|
||||
response = case self.http_method.to_sym
|
||||
when :get,:GET
|
||||
@ -197,6 +199,11 @@ module SwaggerClient
|
||||
request_options.merge(:body => self.outgoing_body)
|
||||
)
|
||||
end
|
||||
|
||||
if Swagger.configuration.debug
|
||||
Swagger.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
||||
end
|
||||
|
||||
Response.new(response)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user