Add logging for API call entry and result

This commit is contained in:
xhh 2015-06-20 12:52:33 +08:00
parent 229ea93627
commit 3b6a3b4a38
4 changed files with 159 additions and 21 deletions

View File

@ -14,6 +14,9 @@ module {{moduleName}}
{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
def self.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: {{classname}}#{{nickname}} ..."
end
{{#allParams}}{{#required}}
# verify the required parameter '{{paramName}}' is set
raise "Missing the required parameter '{{paramName}}' when calling {{nickname}}" if {{{paramName}}}.nil?
@ -52,7 +55,14 @@ module {{moduleName}}
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
{{#returnType}}response = Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('{{{returnType}}}'){{/returnType}}{{^returnType}}Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
result = response.deserialize('{{{returnType}}}')
if Swagger.configuration.debug
Swagger.logger.debug "API called: {{classname}}#{{nickname}}. Result: #{result.inspect}"
end
result{{/returnType}}{{^returnType}}Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: {{classname}}#{{nickname}}"
end
nil{{/returnType}}
end
{{/operation}}

View File

@ -11,6 +11,9 @@ module SwaggerClient
# @option opts [Pet] :body Pet object that needs to be added to the store
# @return [nil]
def self.update_pet(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#update_pet ..."
end
# resource path
@ -38,7 +41,10 @@ module SwaggerClient
auth_names = ['petstore_auth']
Swagger::Request.new(:PUT, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:PUT, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#update_pet"
end
nil
end
@ -48,6 +54,9 @@ module SwaggerClient
# @option opts [Pet] :body Pet object that needs to be added to the store
# @return [nil]
def self.add_pet(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#add_pet ..."
end
# resource path
@ -75,7 +84,10 @@ module SwaggerClient
auth_names = ['petstore_auth']
Swagger::Request.new(:POST, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#add_pet"
end
nil
end
@ -85,6 +97,9 @@ module SwaggerClient
# @option opts [Array<String>] :status Status values that need to be considered for filter
# @return [Array<Pet>]
def self.find_pets_by_status(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#find_pets_by_status ..."
end
# resource path
@ -114,7 +129,11 @@ module SwaggerClient
auth_names = ['petstore_auth']
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('Array<Pet>')
result = response.deserialize('Array<Pet>')
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#find_pets_by_status. Result: #{result.inspect}"
end
result
end
# Finds Pets by tags
@ -123,6 +142,9 @@ module SwaggerClient
# @option opts [Array<String>] :tags Tags to filter by
# @return [Array<Pet>]
def self.find_pets_by_tags(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#find_pets_by_tags ..."
end
# resource path
@ -152,7 +174,11 @@ module SwaggerClient
auth_names = ['petstore_auth']
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('Array<Pet>')
result = response.deserialize('Array<Pet>')
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#find_pets_by_tags. Result: #{result.inspect}"
end
result
end
# Find pet by ID
@ -161,6 +187,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [Pet]
def self.get_pet_by_id(pet_id, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#get_pet_by_id ..."
end
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling get_pet_by_id" if pet_id.nil?
@ -192,7 +221,11 @@ module SwaggerClient
auth_names = ['api_key', 'petstore_auth']
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('Pet')
result = response.deserialize('Pet')
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#get_pet_by_id. Result: #{result.inspect}"
end
result
end
# Updates a pet in the store with form data
@ -203,6 +236,9 @@ module SwaggerClient
# @option opts [String] :status Updated status of the pet
# @return [nil]
def self.update_pet_with_form(pet_id, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#update_pet_with_form ..."
end
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling update_pet_with_form" if pet_id.nil?
@ -235,7 +271,10 @@ module SwaggerClient
auth_names = ['petstore_auth']
Swagger::Request.new(:POST, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#update_pet_with_form"
end
nil
end
@ -246,6 +285,9 @@ module SwaggerClient
# @option opts [String] :api_key
# @return [nil]
def self.delete_pet(pet_id, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#delete_pet ..."
end
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling delete_pet" if pet_id.nil?
@ -277,7 +319,10 @@ module SwaggerClient
auth_names = ['petstore_auth']
Swagger::Request.new(:DELETE, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:DELETE, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#delete_pet"
end
nil
end
@ -289,6 +334,9 @@ module SwaggerClient
# @option opts [file] :file file to upload
# @return [nil]
def self.upload_file(pet_id, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: PetApi#upload_file ..."
end
# verify the required parameter 'pet_id' is set
raise "Missing the required parameter 'pet_id' when calling upload_file" if pet_id.nil?
@ -321,7 +369,10 @@ module SwaggerClient
auth_names = ['petstore_auth']
Swagger::Request.new(:POST, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: PetApi#upload_file"
end
nil
end
end

View File

@ -10,6 +10,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [Hash<String, Integer>]
def self.get_inventory(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: StoreApi#get_inventory ..."
end
# resource path
@ -38,7 +41,11 @@ module SwaggerClient
auth_names = ['api_key']
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('Hash<String, Integer>')
result = response.deserialize('Hash<String, Integer>')
if Swagger.configuration.debug
Swagger.logger.debug "API called: StoreApi#get_inventory. Result: #{result.inspect}"
end
result
end
# Place an order for a pet
@ -47,6 +54,9 @@ module SwaggerClient
# @option opts [Order] :body order placed for purchasing the pet
# @return [Order]
def self.place_order(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: StoreApi#place_order ..."
end
# resource path
@ -75,7 +85,11 @@ module SwaggerClient
auth_names = []
response = Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('Order')
result = response.deserialize('Order')
if Swagger.configuration.debug
Swagger.logger.debug "API called: StoreApi#place_order. Result: #{result.inspect}"
end
result
end
# Find purchase order by ID
@ -84,6 +98,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [Order]
def self.get_order_by_id(order_id, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: StoreApi#get_order_by_id ..."
end
# verify the required parameter 'order_id' is set
raise "Missing the required parameter 'order_id' when calling get_order_by_id" if order_id.nil?
@ -115,7 +132,11 @@ module SwaggerClient
auth_names = []
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('Order')
result = response.deserialize('Order')
if Swagger.configuration.debug
Swagger.logger.debug "API called: StoreApi#get_order_by_id. Result: #{result.inspect}"
end
result
end
# Delete purchase order by ID
@ -124,6 +145,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [nil]
def self.delete_order(order_id, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: StoreApi#delete_order ..."
end
# verify the required parameter 'order_id' is set
raise "Missing the required parameter 'order_id' when calling delete_order" if order_id.nil?
@ -154,7 +178,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:DELETE, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:DELETE, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: StoreApi#delete_order"
end
nil
end
end

View File

@ -11,6 +11,9 @@ module SwaggerClient
# @option opts [User] :body Created user object
# @return [nil]
def self.create_user(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#create_user ..."
end
# resource path
@ -38,7 +41,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:POST, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#create_user"
end
nil
end
@ -48,6 +54,9 @@ module SwaggerClient
# @option opts [Array<User>] :body List of user object
# @return [nil]
def self.create_users_with_array_input(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#create_users_with_array_input ..."
end
# resource path
@ -75,7 +84,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:POST, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#create_users_with_array_input"
end
nil
end
@ -85,6 +97,9 @@ module SwaggerClient
# @option opts [Array<User>] :body List of user object
# @return [nil]
def self.create_users_with_list_input(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#create_users_with_list_input ..."
end
# resource path
@ -112,7 +127,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:POST, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:POST, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#create_users_with_list_input"
end
nil
end
@ -123,6 +141,9 @@ module SwaggerClient
# @option opts [String] :password The password for login in clear text
# @return [String]
def self.login_user(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#login_user ..."
end
# resource path
@ -153,7 +174,11 @@ module SwaggerClient
auth_names = []
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('String')
result = response.deserialize('String')
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#login_user. Result: #{result.inspect}"
end
result
end
# Logs out current logged in user session
@ -161,6 +186,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [nil]
def self.logout_user(opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#logout_user ..."
end
# resource path
@ -188,7 +216,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:GET, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#logout_user"
end
nil
end
@ -198,6 +229,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [User]
def self.get_user_by_name(username, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#get_user_by_name ..."
end
# verify the required parameter 'username' is set
raise "Missing the required parameter 'username' when calling get_user_by_name" if username.nil?
@ -229,7 +263,11 @@ module SwaggerClient
auth_names = []
response = Swagger::Request.new(:GET, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
response.deserialize('User')
result = response.deserialize('User')
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#get_user_by_name. Result: #{result.inspect}"
end
result
end
# Updated user
@ -239,6 +277,9 @@ module SwaggerClient
# @option opts [User] :body Updated user object
# @return [nil]
def self.update_user(username, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#update_user ..."
end
# verify the required parameter 'username' is set
raise "Missing the required parameter 'username' when calling update_user" if username.nil?
@ -269,7 +310,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:PUT, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:PUT, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#update_user"
end
nil
end
@ -279,6 +323,9 @@ module SwaggerClient
# @param [Hash] opts the optional parameters
# @return [nil]
def self.delete_user(username, opts = {})
if Swagger.configuration.debug
Swagger.logger.debug "Calling API: UserApi#delete_user ..."
end
# verify the required parameter 'username' is set
raise "Missing the required parameter 'username' when calling delete_user" if username.nil?
@ -309,7 +356,10 @@ module SwaggerClient
auth_names = []
Swagger::Request.new(:DELETE, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
Swagger::Request.new(:DELETE, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
if Swagger.configuration.debug
Swagger.logger.debug "API called: UserApi#delete_user"
end
nil
end
end