[crystal-lang] Various fixes for Crystal client (#21045)

* fix(crystal): allow users to YAML.dump(model) to ease debug

* fix(crystal): make optional parameters truly optional

* fix(crystal): don't send query parameters when parameter is nil

* fix(crystal): implement cookie Auth

* fix(crystal): fix ameba warnings

* fix(crystal): update sample app specs
This commit is contained in:
Nicolas Rodriguez 2025-04-09 09:04:00 +02:00 committed by GitHub
parent dcd9463e88
commit 6bf528950f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 228 additions and 117 deletions

View File

@ -23,7 +23,7 @@ module {{moduleName}}
{{/required}} {{/required}}
{{/allParams}} {{/allParams}}
# @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}] # @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}]
def {{operationId}}({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) def {{operationId}}({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^required}} = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
{{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}})
{{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}} {{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}}
end end
@ -40,7 +40,7 @@ module {{moduleName}}
{{/required}} {{/required}}
{{/allParams}} {{/allParams}}
# @return [Array<({{{returnType}}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{.}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers # @return [Array<({{{returnType}}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{.}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers
def {{operationId}}_with_http_info({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) def {{operationId}}_with_http_info({{#allParams}}{{paramName}} : {{{dataType}}}{{^required}}?{{/required}}{{^required}} = nil{{/required}}{{^-last}}, {{/-last}}{{/allParams}})
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"Calling API: {{classname}}.{{operationId}} ..."} Log.debug {"Calling API: {{classname}}.{{operationId}} ..."}
end end
@ -127,10 +127,13 @@ module {{moduleName}}
# resource path # resource path
local_var_path = "{{{path}}}"{{#pathParams}}.sub("{" + "{{baseName}}" + "}", URI.encode_path({{paramName}}.to_s){{^strictSpecBehavior}}.gsub("%2F", "/"){{/strictSpecBehavior}}){{/pathParams}} local_var_path = "{{{path}}}"{{#pathParams}}.sub("{" + "{{baseName}}" + "}", URI.encode_path({{paramName}}.to_s){{^strictSpecBehavior}}.gsub("%2F", "/"){{/strictSpecBehavior}}){{/pathParams}}
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
{{#queryParams}} {{#queryParams}}
query_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.to_s unless {{{paramName}}}.nil?{{/collectionFormat}} query_params["{{{baseName}}}"] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}) unless {{{paramName}}}.nil?{{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}.to_s unless {{{paramName}}}.nil?{{/collectionFormat}}
{{/queryParams}} {{/queryParams}}
# header parameters # header parameters
@ -170,6 +173,7 @@ module {{moduleName}}
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

View File

@ -50,14 +50,15 @@ module {{moduleName}}
# @param [Hash] header_params Header parameters # @param [Hash] header_params Header parameters
# @param [Hash] query_params Query parameters # @param [Hash] query_params Query parameters
# @param [String] auth_names Authentication scheme name # @param [String] auth_names Authentication scheme name
def update_params_for_auth!(header_params, query_params, auth_names) def update_params_for_auth!(header_params, query_params, cookie_params, auth_names)
auth_names.each do |auth_name| auth_names.each do |auth_name|
auth_setting = @config.auth_settings[auth_name] auth_setting = @config.auth_settings[auth_name]
next unless auth_setting next unless auth_setting
case auth_setting[:in] case auth_setting[:in]
when "header" then header_params[auth_setting[:key]] = auth_setting[:value] when "header" then header_params[auth_setting[:key]] = auth_setting[:value]
when "query" then query_params[auth_setting[:key]] = auth_setting[:value] when "query" then query_params[auth_setting[:key]] = auth_setting[:value]
else raise ArgumentError.new("Authentication token must be in `query` of `header`") when "cookie" then cookie_params[auth_setting[:key]] = auth_setting[:value]
else raise ArgumentError.new("Authentication token must be in `cookie`, `query` or `header`")
end end
end end
end end
@ -119,7 +120,7 @@ module {{moduleName}}
# #
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements: # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
# the data deserialized from response body (could be nil), response status code and response headers. # the data deserialized from response body (could be nil), response status code and response headers.
def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, form_params = {} of Symbol => (String | ::File)) def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, cookie_params = {} of String => String, form_params = {} of Symbol => (String | ::File))
#ssl_options = { #ssl_options = {
# :ca_file => @config.ssl_ca_file, # :ca_file => @config.ssl_ca_file,
# :verify => @config.ssl_verify, # :verify => @config.ssl_verify,
@ -128,7 +129,7 @@ module {{moduleName}}
# :client_key => @config.ssl_client_key # :client_key => @config.ssl_client_key
#} #}
update_params_for_auth! header_params, query_params, auth_names update_params_for_auth! header_params, query_params, cookie_params, auth_names
if !post_body.nil? && !post_body.empty? if !post_body.nil? && !post_body.empty?
# use JSON string in the payload # use JSON string in the payload
@ -143,7 +144,7 @@ module {{moduleName}}
build_request_url(path, operation), build_request_url(path, operation),
params: query_params, params: query_params,
headers: header_params, headers: header_params,
#cookies: cookie_params, # TODO add cookies support cookies: cookie_params,
form: form_or_body, form: form_or_body,
logging: @config.debugging, logging: @config.debugging,
handle_errors: false handle_errors: false

View File

@ -2,6 +2,7 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module {{moduleName}} module {{moduleName}}

View File

@ -3,6 +3,7 @@
{{/description}} {{/description}}
class {{classname}}{{#parent}} < {{{.}}}{{/parent}} class {{classname}}{{#parent}} < {{{.}}}{{/parent}}
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
{{#hasRequired}} {{#hasRequired}}
# Required properties # Required properties
@ -269,16 +270,16 @@
{{/vars}} {{/vars}}
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class{{#vars}} && self.class == other.class{{#vars}} &&
{{name}} == o.{{name}}{{/vars}}{{#parent}} && super(o){{/parent}} {{name}} == other.{{name}}{{/vars}}{{#parent}} && super(other){{/parent}}
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -9,9 +9,10 @@ Spectator.describe Petstore::ApiClient do
header_params = {} of String => String header_params = {} of String => String
query_params = {} of String => String query_params = {} of String => String
cookie_params = {} of String => String
api_client = Petstore::ApiClient.new(config) api_client = Petstore::ApiClient.new(config)
api_client.update_params_for_auth!(header_params, query_params, ["petstore_auth"]) api_client.update_params_for_auth!(header_params, query_params, cookie_params, ["petstore_auth"])
expect(header_params["Authorization"]).to eq "Bearer xxx" expect(header_params["Authorization"]).to eq "Bearer xxx"
expect(query_params.size).to eq 0 expect(query_params.size).to eq 0
@ -26,9 +27,10 @@ Spectator.describe Petstore::ApiClient do
header_params = {} of String => String header_params = {} of String => String
query_params = {} of String => String query_params = {} of String => String
cookie_params = {} of String => String
api_client = Petstore::ApiClient.new(config) api_client = Petstore::ApiClient.new(config)
api_client.update_params_for_auth!(header_params, query_params, ["api_key"]) api_client.update_params_for_auth!(header_params, query_params, cookie_params, ["api_key"])
expect(header_params["api_key"]).to eq "xxx" expect(header_params["api_key"]).to eq "xxx"
expect(query_params.empty?).to be_true expect(query_params.empty?).to be_true
@ -43,9 +45,10 @@ Spectator.describe Petstore::ApiClient do
header_params = {} of String => String header_params = {} of String => String
query_params = {} of String => String query_params = {} of String => String
cookie_params = {} of String => String
api_client = Petstore::ApiClient.new(config) api_client = Petstore::ApiClient.new(config)
api_client.update_params_for_auth!(header_params, query_params, ["api_key"]) api_client.update_params_for_auth!(header_params, query_params, cookie_params, ["api_key"])
expect(header_params["api_key"]).to eq "Token xxx" expect(header_params["api_key"]).to eq "Token xxx"
expect(query_params.empty?).to be_true expect(query_params.empty?).to be_true

View File

@ -63,6 +63,9 @@ module Petstore
# resource path # resource path
local_var_path = "/fake/parameter-name-mapping" local_var_path = "/fake/parameter-name-mapping"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
query_params["type"] = _type.to_s unless _type.nil? query_params["type"] = _type.to_s unless _type.nil?
@ -94,6 +97,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: FakeApi#get_parameter_name_mapping\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: FakeApi#get_parameter_name_mapping\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

View File

@ -41,6 +41,9 @@ module Petstore
# resource path # resource path
local_var_path = "/pet" local_var_path = "/pet"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -71,6 +74,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#add_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#add_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -82,7 +86,7 @@ module Petstore
# #
# @param pet_id [Int64] Pet id to delete # @param pet_id [Int64] Pet id to delete
# @return [nil] # @return [nil]
def delete_pet(pet_id : Int64, api_key : String?) def delete_pet(pet_id : Int64, api_key : String? = nil)
delete_pet_with_http_info(pet_id, api_key) delete_pet_with_http_info(pet_id, api_key)
nil nil
end end
@ -91,7 +95,7 @@ module Petstore
# #
# @param pet_id [Int64] Pet id to delete # @param pet_id [Int64] Pet id to delete
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def delete_pet_with_http_info(pet_id : Int64, api_key : String?) def delete_pet_with_http_info(pet_id : Int64, api_key : String? = nil)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"Calling API: PetApi.delete_pet ..."} Log.debug {"Calling API: PetApi.delete_pet ..."}
end end
@ -102,6 +106,9 @@ module Petstore
# resource path # resource path
local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/")) local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -129,6 +136,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#delete_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#delete_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -160,9 +168,12 @@ module Petstore
# resource path # resource path
local_var_path = "/pet/findByStatus" local_var_path = "/pet/findByStatus"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
query_params["status"] = @api_client.build_collection_param(status, :csv) query_params["status"] = @api_client.build_collection_param(status, :csv) unless status.nil?
# header parameters # header parameters
header_params = Hash(String, String).new header_params = Hash(String, String).new
@ -189,6 +200,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#find_pets_by_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#find_pets_by_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -220,9 +232,12 @@ module Petstore
# resource path # resource path
local_var_path = "/pet/findByTags" local_var_path = "/pet/findByTags"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
query_params["tags"] = @api_client.build_collection_param(tags, :csv) query_params["tags"] = @api_client.build_collection_param(tags, :csv) unless tags.nil?
# header parameters # header parameters
header_params = Hash(String, String).new header_params = Hash(String, String).new
@ -249,6 +264,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#find_pets_by_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#find_pets_by_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -280,6 +296,9 @@ module Petstore
# resource path # resource path
local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/")) local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -308,6 +327,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#get_pet_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#get_pet_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -339,6 +359,9 @@ module Petstore
# resource path # resource path
local_var_path = "/pet" local_var_path = "/pet"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -369,6 +392,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#update_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#update_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -380,7 +404,7 @@ module Petstore
# #
# @param pet_id [Int64] ID of pet that needs to be updated # @param pet_id [Int64] ID of pet that needs to be updated
# @return [nil] # @return [nil]
def update_pet_with_form(pet_id : Int64, name : String?, status : String?) def update_pet_with_form(pet_id : Int64, name : String? = nil, status : String? = nil)
update_pet_with_form_with_http_info(pet_id, name, status) update_pet_with_form_with_http_info(pet_id, name, status)
nil nil
end end
@ -389,7 +413,7 @@ module Petstore
# #
# @param pet_id [Int64] ID of pet that needs to be updated # @param pet_id [Int64] ID of pet that needs to be updated
# @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
def update_pet_with_form_with_http_info(pet_id : Int64, name : String?, status : String?) def update_pet_with_form_with_http_info(pet_id : Int64, name : String? = nil, status : String? = nil)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"Calling API: PetApi.update_pet_with_form ..."} Log.debug {"Calling API: PetApi.update_pet_with_form ..."}
end end
@ -400,6 +424,9 @@ module Petstore
# resource path # resource path
local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/")) local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -430,6 +457,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#update_pet_with_form\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#update_pet_with_form\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -441,7 +469,7 @@ module Petstore
# #
# @param pet_id [Int64] ID of pet to update # @param pet_id [Int64] ID of pet to update
# @return [ApiResponse] # @return [ApiResponse]
def upload_file(pet_id : Int64, additional_metadata : String?, file : ::File?) def upload_file(pet_id : Int64, additional_metadata : String? = nil, file : ::File? = nil)
data, _status_code, _headers = upload_file_with_http_info(pet_id, additional_metadata, file) data, _status_code, _headers = upload_file_with_http_info(pet_id, additional_metadata, file)
data data
end end
@ -450,7 +478,7 @@ module Petstore
# #
# @param pet_id [Int64] ID of pet to update # @param pet_id [Int64] ID of pet to update
# @return [Array<(ApiResponse, Integer, Hash)>] ApiResponse data, response status code and response headers # @return [Array<(ApiResponse, Integer, Hash)>] ApiResponse data, response status code and response headers
def upload_file_with_http_info(pet_id : Int64, additional_metadata : String?, file : ::File?) def upload_file_with_http_info(pet_id : Int64, additional_metadata : String? = nil, file : ::File? = nil)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"Calling API: PetApi.upload_file ..."} Log.debug {"Calling API: PetApi.upload_file ..."}
end end
@ -461,6 +489,9 @@ module Petstore
# resource path # resource path
local_var_path = "/pet/{petId}/uploadImage".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/")) local_var_path = "/pet/{petId}/uploadImage".sub("{" + "petId" + "}", URI.encode_path(pet_id.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -493,6 +524,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: PetApi#upload_file\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: PetApi#upload_file\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

View File

@ -41,6 +41,9 @@ module Petstore
# resource path # resource path
local_var_path = "/store/order/{orderId}".sub("{" + "orderId" + "}", URI.encode_path(order_id.to_s).gsub("%2F", "/")) local_var_path = "/store/order/{orderId}".sub("{" + "orderId" + "}", URI.encode_path(order_id.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -67,6 +70,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: StoreApi#delete_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: StoreApi#delete_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -92,6 +96,9 @@ module Petstore
# resource path # resource path
local_var_path = "/store/inventory" local_var_path = "/store/inventory"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -120,6 +127,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: StoreApi#get_inventory\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: StoreApi#get_inventory\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -159,6 +167,9 @@ module Petstore
# resource path # resource path
local_var_path = "/store/order/{orderId}".sub("{" + "orderId" + "}", URI.encode_path(order_id.to_s).gsub("%2F", "/")) local_var_path = "/store/order/{orderId}".sub("{" + "orderId" + "}", URI.encode_path(order_id.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -187,6 +198,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: StoreApi#get_order_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: StoreApi#get_order_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -218,6 +230,9 @@ module Petstore
# resource path # resource path
local_var_path = "/store/order" local_var_path = "/store/order"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -248,6 +263,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: StoreApi#place_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: StoreApi#place_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

View File

@ -41,6 +41,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user" local_var_path = "/user"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -69,6 +72,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#create_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#create_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -100,6 +104,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/createWithArray" local_var_path = "/user/createWithArray"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -128,6 +135,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#create_users_with_array_input\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#create_users_with_array_input\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -159,6 +167,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/createWithList" local_var_path = "/user/createWithList"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -187,6 +198,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#create_users_with_list_input\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#create_users_with_list_input\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -218,6 +230,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/{username}".sub("{" + "username" + "}", URI.encode_path(username.to_s).gsub("%2F", "/")) local_var_path = "/user/{username}".sub("{" + "username" + "}", URI.encode_path(username.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -244,6 +259,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#delete_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#delete_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -275,6 +291,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/{username}".sub("{" + "username" + "}", URI.encode_path(username.to_s).gsub("%2F", "/")) local_var_path = "/user/{username}".sub("{" + "username" + "}", URI.encode_path(username.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -303,6 +322,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#get_user_by_name\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#get_user_by_name\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -345,6 +365,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/login" local_var_path = "/user/login"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
query_params["username"] = username.to_s unless username.nil? query_params["username"] = username.to_s unless username.nil?
@ -375,6 +398,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#login_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#login_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -400,6 +424,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/logout" local_var_path = "/user/logout"
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -426,6 +453,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#logout_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#logout_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
@ -463,6 +491,9 @@ module Petstore
# resource path # resource path
local_var_path = "/user/{username}".sub("{" + "username" + "}", URI.encode_path(username.to_s).gsub("%2F", "/")) local_var_path = "/user/{username}".sub("{" + "username" + "}", URI.encode_path(username.to_s).gsub("%2F", "/"))
# cookie parameters
cookie_params = Hash(String, String).new
# query parameters # query parameters
query_params = Hash(String, String).new query_params = Hash(String, String).new
@ -491,6 +522,7 @@ module Petstore
auth_names, auth_names,
header_params, header_params,
query_params, query_params,
cookie_params,
form_params) form_params)
if @api_client.config.debugging if @api_client.config.debugging
Log.debug {"API called: UserApi#update_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} Log.debug {"API called: UserApi#update_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}

View File

@ -58,14 +58,15 @@ module Petstore
# @param [Hash] header_params Header parameters # @param [Hash] header_params Header parameters
# @param [Hash] query_params Query parameters # @param [Hash] query_params Query parameters
# @param [String] auth_names Authentication scheme name # @param [String] auth_names Authentication scheme name
def update_params_for_auth!(header_params, query_params, auth_names) def update_params_for_auth!(header_params, query_params, cookie_params, auth_names)
auth_names.each do |auth_name| auth_names.each do |auth_name|
auth_setting = @config.auth_settings[auth_name] auth_setting = @config.auth_settings[auth_name]
next unless auth_setting next unless auth_setting
case auth_setting[:in] case auth_setting[:in]
when "header" then header_params[auth_setting[:key]] = auth_setting[:value] when "header" then header_params[auth_setting[:key]] = auth_setting[:value]
when "query" then query_params[auth_setting[:key]] = auth_setting[:value] when "query" then query_params[auth_setting[:key]] = auth_setting[:value]
else raise ArgumentError.new("Authentication token must be in `query` of `header`") when "cookie" then cookie_params[auth_setting[:key]] = auth_setting[:value]
else raise ArgumentError.new("Authentication token must be in `cookie`, `query` or `header`")
end end
end end
end end
@ -127,7 +128,7 @@ module Petstore
# #
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements: # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
# the data deserialized from response body (could be nil), response status code and response headers. # the data deserialized from response body (could be nil), response status code and response headers.
def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, form_params = {} of Symbol => (String | ::File)) def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, cookie_params = {} of String => String, form_params = {} of Symbol => (String | ::File))
#ssl_options = { #ssl_options = {
# :ca_file => @config.ssl_ca_file, # :ca_file => @config.ssl_ca_file,
# :verify => @config.ssl_verify, # :verify => @config.ssl_verify,
@ -136,7 +137,7 @@ module Petstore
# :client_key => @config.ssl_client_key # :client_key => @config.ssl_client_key
#} #}
update_params_for_auth! header_params, query_params, auth_names update_params_for_auth! header_params, query_params, cookie_params, auth_names
if !post_body.nil? && !post_body.empty? if !post_body.nil? && !post_body.empty?
# use JSON string in the payload # use JSON string in the payload
@ -151,7 +152,7 @@ module Petstore
build_request_url(path, operation), build_request_url(path, operation),
params: query_params, params: query_params,
headers: header_params, headers: header_params,
#cookies: cookie_params, # TODO add cookies support cookies: cookie_params,
form: form_or_body, form: form_or_body,
logging: @config.debugging, logging: @config.debugging,
handle_errors: false handle_errors: false

View File

@ -10,11 +10,13 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
class AnotherPropertyNameMapping class AnotherPropertyNameMapping
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Optional properties # Optional properties
@[JSON::Field(key: "http_debug_operation", type: String?, nillable: true, emit_null: false)] @[JSON::Field(key: "http_debug_operation", type: String?, nillable: true, emit_null: false)]
@ -49,19 +51,19 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
http_debug_operation == o.http_debug_operation && http_debug_operation == other.http_debug_operation &&
underscore_type == o.underscore_type && underscore_type == other.underscore_type &&
_type == o._type && _type == other._type &&
type_with_underscore == o.type_with_underscore type_with_underscore == other.type_with_underscore
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,12 +10,14 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
# Describes the result of uploading an image resource # Describes the result of uploading an image resource
class ApiResponse class ApiResponse
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Optional properties # Optional properties
@[JSON::Field(key: "code", type: Int32?, nillable: true, emit_null: false)] @[JSON::Field(key: "code", type: Int32?, nillable: true, emit_null: false)]
@ -47,18 +49,18 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
code == o.code && code == other.code &&
_type == o._type && _type == other._type &&
message == o.message message == other.message
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,12 +10,14 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
# A category for a pet # A category for a pet
class Category class Category
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Optional properties # Optional properties
@[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)]
@ -61,17 +63,17 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
id == o.id && id == other.id &&
name == o.name name == other.name
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,11 +10,13 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
class FormatTest class FormatTest
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Required properties # Required properties
@[JSON::Field(key: "number", type: Float64, nillable: false, emit_null: false)] @[JSON::Field(key: "number", type: Float64, nillable: false, emit_null: false)]
@ -283,31 +285,31 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
integer == o.integer && integer == other.integer &&
int32 == o.int32 && int32 == other.int32 &&
int64 == o.int64 && int64 == other.int64 &&
number == o.number && number == other.number &&
float == o.float && float == other.float &&
double == o.double && double == other.double &&
decimal == o.decimal && decimal == other.decimal &&
string == o.string && string == other.string &&
byte == o.byte && byte == other.byte &&
binary == o.binary && binary == other.binary &&
date == o.date && date == other.date &&
date_time == o.date_time && date_time == other.date_time &&
uuid == o.uuid && uuid == other.uuid &&
password == o.password && password == other.password &&
pattern_with_digits == o.pattern_with_digits && pattern_with_digits == other.pattern_with_digits &&
pattern_with_digits_and_delimiter == o.pattern_with_digits_and_delimiter pattern_with_digits_and_delimiter == other.pattern_with_digits_and_delimiter
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,12 +10,14 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
# An order for a pets from the pet store # An order for a pets from the pet store
class Order class Order
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Optional properties # Optional properties
@[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)]
@ -92,21 +94,21 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
id == o.id && id == other.id &&
pet_id == o.pet_id && pet_id == other.pet_id &&
quantity == o.quantity && quantity == other.quantity &&
ship_date == o.ship_date && ship_date == other.ship_date &&
status == o.status && status == other.status &&
complete == o.complete complete == other.complete
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,12 +10,14 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
# A pet for sale in the pet store # A pet for sale in the pet store
class Pet class Pet
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Required properties # Required properties
@[JSON::Field(key: "name", type: String, nillable: false, emit_null: false)] @[JSON::Field(key: "name", type: String, nillable: false, emit_null: false)]
@ -93,21 +95,21 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
id == o.id && id == other.id &&
category == o.category && category == other.category &&
name == o.name && name == other.name &&
photo_urls == o.photo_urls && photo_urls == other.photo_urls &&
tags == o.tags && tags == other.tags &&
status == o.status status == other.status
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,12 +10,14 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
# A tag for a pet # A tag for a pet
class Tag class Tag
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Optional properties # Optional properties
@[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)]
@ -44,17 +46,17 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
id == o.id && id == other.id &&
name == o.name name == other.name
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.

View File

@ -10,12 +10,14 @@
require "big" require "big"
require "json" require "json"
require "yaml"
require "time" require "time"
module Petstore module Petstore
# A User who is purchasing from the pet store # A User who is purchasing from the pet store
class User class User
include JSON::Serializable include JSON::Serializable
include YAML::Serializable
# Optional properties # Optional properties
@[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)]
@ -63,23 +65,23 @@ module Petstore
# Checks equality by comparing each attribute. # Checks equality by comparing each attribute.
# @param [Object] Object to be compared # @param [Object] Object to be compared
def ==(o) def ==(other)
return true if self.same?(o) return true if self.same?(other)
self.class == o.class && self.class == other.class &&
id == o.id && id == other.id &&
username == o.username && username == other.username &&
first_name == o.first_name && first_name == other.first_name &&
last_name == o.last_name && last_name == other.last_name &&
email == o.email && email == other.email &&
password == o.password && password == other.password &&
phone == o.phone && phone == other.phone &&
user_status == o.user_status user_status == other.user_status
end end
# @see the `==` method # @see the `==` method
# @param [Object] Object to be compared # @param [Object] Object to be compared
def eql?(o) def eql?(other)
self == o self == other
end end
# Calculates hash code according to all attributes. # Calculates hash code according to all attributes.