diff --git a/modules/openapi-generator/src/main/resources/crystal/api.mustache b/modules/openapi-generator/src/main/resources/crystal/api.mustache index 18c3d4d41e1a..0bf7d2dea886 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api.mustache @@ -23,7 +23,7 @@ module {{moduleName}} {{/required}} {{/allParams}} # @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{{/returnType}}{{^returnType}}nil{{/returnType}} end @@ -40,7 +40,7 @@ module {{moduleName}} {{/required}} {{/allParams}} # @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 Log.debug {"Calling API: {{classname}}.{{operationId}} ..."} end @@ -127,10 +127,13 @@ module {{moduleName}} # resource path 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_params = Hash(String, String).new {{#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}} # header parameters @@ -170,6 +173,7 @@ module {{moduleName}} auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} diff --git a/modules/openapi-generator/src/main/resources/crystal/api_client.mustache b/modules/openapi-generator/src/main/resources/crystal/api_client.mustache index 6092a89911c6..b74d38f191b3 100644 --- a/modules/openapi-generator/src/main/resources/crystal/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/api_client.mustache @@ -50,14 +50,15 @@ module {{moduleName}} # @param [Hash] header_params Header parameters # @param [Hash] query_params Query parameters # @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_setting = @config.auth_settings[auth_name] next unless auth_setting case auth_setting[:in] when "header" then header_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 @@ -119,7 +120,7 @@ module {{moduleName}} # # @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. - 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 = { # :ca_file => @config.ssl_ca_file, # :verify => @config.ssl_verify, @@ -128,7 +129,7 @@ module {{moduleName}} # :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? # use JSON string in the payload @@ -143,7 +144,7 @@ module {{moduleName}} build_request_url(path, operation), params: query_params, headers: header_params, - #cookies: cookie_params, # TODO add cookies support + cookies: cookie_params, form: form_or_body, logging: @config.debugging, handle_errors: false diff --git a/modules/openapi-generator/src/main/resources/crystal/model.mustache b/modules/openapi-generator/src/main/resources/crystal/model.mustache index 3330b7ad234f..8b06bff97597 100644 --- a/modules/openapi-generator/src/main/resources/crystal/model.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/model.mustache @@ -2,6 +2,7 @@ require "big" require "json" +require "yaml" require "time" module {{moduleName}} diff --git a/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache b/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache index ba58fb06828e..3daff8530465 100644 --- a/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/crystal/partial_model_generic.mustache @@ -3,6 +3,7 @@ {{/description}} class {{classname}}{{#parent}} < {{{.}}}{{/parent}} include JSON::Serializable + include YAML::Serializable {{#hasRequired}} # Required properties @@ -269,16 +270,16 @@ {{/vars}} # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class{{#vars}} && - {{name}} == o.{{name}}{{/vars}}{{#parent}} && super(o){{/parent}} + def ==(other) + return true if self.same?(other) + self.class == other.class{{#vars}} && + {{name}} == other.{{name}}{{/vars}}{{#parent}} && super(other){{/parent}} end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/bin/ameba b/samples/client/petstore/crystal/bin/ameba index c88ac4a8d026..e708bbed7199 100755 Binary files a/samples/client/petstore/crystal/bin/ameba and b/samples/client/petstore/crystal/bin/ameba differ diff --git a/samples/client/petstore/crystal/spec/api_client_spec.cr b/samples/client/petstore/crystal/spec/api_client_spec.cr index eb6ee5723678..767764436a92 100644 --- a/samples/client/petstore/crystal/spec/api_client_spec.cr +++ b/samples/client/petstore/crystal/spec/api_client_spec.cr @@ -9,9 +9,10 @@ Spectator.describe Petstore::ApiClient do header_params = {} of String => String query_params = {} of String => String + cookie_params = {} of String => String 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(query_params.size).to eq 0 @@ -26,9 +27,10 @@ Spectator.describe Petstore::ApiClient do header_params = {} of String => String query_params = {} of String => String + cookie_params = {} of String => String 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(query_params.empty?).to be_true @@ -43,9 +45,10 @@ Spectator.describe Petstore::ApiClient do header_params = {} of String => String query_params = {} of String => String + cookie_params = {} of String => String 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(query_params.empty?).to be_true diff --git a/samples/client/petstore/crystal/src/petstore/api/fake_api.cr b/samples/client/petstore/crystal/src/petstore/api/fake_api.cr index de491cde9194..63b653670e51 100644 --- a/samples/client/petstore/crystal/src/petstore/api/fake_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/fake_api.cr @@ -63,6 +63,9 @@ module Petstore # resource path local_var_path = "/fake/parameter-name-mapping" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new query_params["type"] = _type.to_s unless _type.nil? @@ -94,6 +97,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: FakeApi#get_parameter_name_mapping\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} diff --git a/samples/client/petstore/crystal/src/petstore/api/pet_api.cr b/samples/client/petstore/crystal/src/petstore/api/pet_api.cr index 613d925af861..3d53e092bcd6 100644 --- a/samples/client/petstore/crystal/src/petstore/api/pet_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/pet_api.cr @@ -41,6 +41,9 @@ module Petstore # resource path local_var_path = "/pet" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -71,6 +74,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 # @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) nil end @@ -91,7 +95,7 @@ module Petstore # # @param pet_id [Int64] Pet id to delete # @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 Log.debug {"Calling API: PetApi.delete_pet ..."} end @@ -102,6 +106,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -129,6 +136,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: PetApi#delete_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -160,9 +168,12 @@ module Petstore # resource path local_var_path = "/pet/findByStatus" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters 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_params = Hash(String, String).new @@ -189,6 +200,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 local_var_path = "/pet/findByTags" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters 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_params = Hash(String, String).new @@ -249,6 +264,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 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_params = Hash(String, String).new @@ -308,6 +327,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 local_var_path = "/pet" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -369,6 +392,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 # @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) nil end @@ -389,7 +413,7 @@ module Petstore # # @param pet_id [Int64] ID of pet that needs to be updated # @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 Log.debug {"Calling API: PetApi.update_pet_with_form ..."} end @@ -400,6 +424,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -430,6 +457,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 # @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 end @@ -450,7 +478,7 @@ module Petstore # # @param pet_id [Int64] ID of pet to update # @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 Log.debug {"Calling API: PetApi.upload_file ..."} end @@ -461,6 +489,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -493,6 +524,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: PetApi#upload_file\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} diff --git a/samples/client/petstore/crystal/src/petstore/api/store_api.cr b/samples/client/petstore/crystal/src/petstore/api/store_api.cr index 87ed25f1ff4d..ae2479ca06b3 100644 --- a/samples/client/petstore/crystal/src/petstore/api/store_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/store_api.cr @@ -41,6 +41,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -67,6 +70,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: StoreApi#delete_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -92,6 +96,9 @@ module Petstore # resource path local_var_path = "/store/inventory" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -120,6 +127,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: StoreApi#get_inventory\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -159,6 +167,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -187,6 +198,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 local_var_path = "/store/order" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -248,6 +263,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: StoreApi#place_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} diff --git a/samples/client/petstore/crystal/src/petstore/api/user_api.cr b/samples/client/petstore/crystal/src/petstore/api/user_api.cr index c94493b05005..74b9d43e3725 100644 --- a/samples/client/petstore/crystal/src/petstore/api/user_api.cr +++ b/samples/client/petstore/crystal/src/petstore/api/user_api.cr @@ -41,6 +41,9 @@ module Petstore # resource path local_var_path = "/user" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -69,6 +72,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: UserApi#create_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -100,6 +104,9 @@ module Petstore # resource path local_var_path = "/user/createWithArray" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -128,6 +135,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 local_var_path = "/user/createWithList" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -187,6 +198,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 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_params = Hash(String, String).new @@ -244,6 +259,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: UserApi#delete_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -275,6 +291,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -303,6 +322,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging 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 local_var_path = "/user/login" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new query_params["username"] = username.to_s unless username.nil? @@ -375,6 +398,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: UserApi#login_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -400,6 +424,9 @@ module Petstore # resource path local_var_path = "/user/logout" + # cookie parameters + cookie_params = Hash(String, String).new + # query parameters query_params = Hash(String, String).new @@ -426,6 +453,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: UserApi#logout_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} @@ -463,6 +491,9 @@ module Petstore # resource path 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_params = Hash(String, String).new @@ -491,6 +522,7 @@ module Petstore auth_names, header_params, query_params, + cookie_params, form_params) if @api_client.config.debugging Log.debug {"API called: UserApi#update_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"} diff --git a/samples/client/petstore/crystal/src/petstore/api_client.cr b/samples/client/petstore/crystal/src/petstore/api_client.cr index 256c623056d9..b2479e7aae43 100644 --- a/samples/client/petstore/crystal/src/petstore/api_client.cr +++ b/samples/client/petstore/crystal/src/petstore/api_client.cr @@ -58,14 +58,15 @@ module Petstore # @param [Hash] header_params Header parameters # @param [Hash] query_params Query parameters # @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_setting = @config.auth_settings[auth_name] next unless auth_setting case auth_setting[:in] when "header" then header_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 @@ -127,7 +128,7 @@ module Petstore # # @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. - 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 = { # :ca_file => @config.ssl_ca_file, # :verify => @config.ssl_verify, @@ -136,7 +137,7 @@ module Petstore # :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? # use JSON string in the payload @@ -151,7 +152,7 @@ module Petstore build_request_url(path, operation), params: query_params, headers: header_params, - #cookies: cookie_params, # TODO add cookies support + cookies: cookie_params, form: form_or_body, logging: @config.debugging, handle_errors: false diff --git a/samples/client/petstore/crystal/src/petstore/models/another_property_name_mapping.cr b/samples/client/petstore/crystal/src/petstore/models/another_property_name_mapping.cr index 3d4789fa45a6..905e388481ad 100644 --- a/samples/client/petstore/crystal/src/petstore/models/another_property_name_mapping.cr +++ b/samples/client/petstore/crystal/src/petstore/models/another_property_name_mapping.cr @@ -10,11 +10,13 @@ require "big" require "json" +require "yaml" require "time" module Petstore class AnotherPropertyNameMapping include JSON::Serializable + include YAML::Serializable # Optional properties @[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. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - http_debug_operation == o.http_debug_operation && - underscore_type == o.underscore_type && - _type == o._type && - type_with_underscore == o.type_with_underscore + def ==(other) + return true if self.same?(other) + self.class == other.class && + http_debug_operation == other.http_debug_operation && + underscore_type == other.underscore_type && + _type == other._type && + type_with_underscore == other.type_with_underscore end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/api_response.cr b/samples/client/petstore/crystal/src/petstore/models/api_response.cr index a77a0e108b8d..985f79f46243 100644 --- a/samples/client/petstore/crystal/src/petstore/models/api_response.cr +++ b/samples/client/petstore/crystal/src/petstore/models/api_response.cr @@ -10,12 +10,14 @@ require "big" require "json" +require "yaml" require "time" module Petstore # Describes the result of uploading an image resource class ApiResponse include JSON::Serializable + include YAML::Serializable # Optional properties @[JSON::Field(key: "code", type: Int32?, nillable: true, emit_null: false)] @@ -47,18 +49,18 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - code == o.code && - _type == o._type && - message == o.message + def ==(other) + return true if self.same?(other) + self.class == other.class && + code == other.code && + _type == other._type && + message == other.message end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/category.cr b/samples/client/petstore/crystal/src/petstore/models/category.cr index 622e67e40873..f690db207604 100644 --- a/samples/client/petstore/crystal/src/petstore/models/category.cr +++ b/samples/client/petstore/crystal/src/petstore/models/category.cr @@ -10,12 +10,14 @@ require "big" require "json" +require "yaml" require "time" module Petstore # A category for a pet class Category include JSON::Serializable + include YAML::Serializable # Optional properties @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @@ -61,17 +63,17 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - id == o.id && - name == o.name + def ==(other) + return true if self.same?(other) + self.class == other.class && + id == other.id && + name == other.name end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/format_test.cr b/samples/client/petstore/crystal/src/petstore/models/format_test.cr index 570a1b6df517..4a19a070db86 100644 --- a/samples/client/petstore/crystal/src/petstore/models/format_test.cr +++ b/samples/client/petstore/crystal/src/petstore/models/format_test.cr @@ -10,11 +10,13 @@ require "big" require "json" +require "yaml" require "time" module Petstore class FormatTest include JSON::Serializable + include YAML::Serializable # Required properties @[JSON::Field(key: "number", type: Float64, nillable: false, emit_null: false)] @@ -283,31 +285,31 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - integer == o.integer && - int32 == o.int32 && - int64 == o.int64 && - number == o.number && - float == o.float && - double == o.double && - decimal == o.decimal && - string == o.string && - byte == o.byte && - binary == o.binary && - date == o.date && - date_time == o.date_time && - uuid == o.uuid && - password == o.password && - pattern_with_digits == o.pattern_with_digits && - pattern_with_digits_and_delimiter == o.pattern_with_digits_and_delimiter + def ==(other) + return true if self.same?(other) + self.class == other.class && + integer == other.integer && + int32 == other.int32 && + int64 == other.int64 && + number == other.number && + float == other.float && + double == other.double && + decimal == other.decimal && + string == other.string && + byte == other.byte && + binary == other.binary && + date == other.date && + date_time == other.date_time && + uuid == other.uuid && + password == other.password && + pattern_with_digits == other.pattern_with_digits && + pattern_with_digits_and_delimiter == other.pattern_with_digits_and_delimiter end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/order.cr b/samples/client/petstore/crystal/src/petstore/models/order.cr index 056d81b0378f..3a63d89d68be 100644 --- a/samples/client/petstore/crystal/src/petstore/models/order.cr +++ b/samples/client/petstore/crystal/src/petstore/models/order.cr @@ -10,12 +10,14 @@ require "big" require "json" +require "yaml" require "time" module Petstore # An order for a pets from the pet store class Order include JSON::Serializable + include YAML::Serializable # Optional properties @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @@ -92,21 +94,21 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - id == o.id && - pet_id == o.pet_id && - quantity == o.quantity && - ship_date == o.ship_date && - status == o.status && - complete == o.complete + def ==(other) + return true if self.same?(other) + self.class == other.class && + id == other.id && + pet_id == other.pet_id && + quantity == other.quantity && + ship_date == other.ship_date && + status == other.status && + complete == other.complete end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/pet.cr b/samples/client/petstore/crystal/src/petstore/models/pet.cr index 50b13cc251ba..d0ff4c3ecc04 100644 --- a/samples/client/petstore/crystal/src/petstore/models/pet.cr +++ b/samples/client/petstore/crystal/src/petstore/models/pet.cr @@ -10,12 +10,14 @@ require "big" require "json" +require "yaml" require "time" module Petstore # A pet for sale in the pet store class Pet include JSON::Serializable + include YAML::Serializable # Required properties @[JSON::Field(key: "name", type: String, nillable: false, emit_null: false)] @@ -93,21 +95,21 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - id == o.id && - category == o.category && - name == o.name && - photo_urls == o.photo_urls && - tags == o.tags && - status == o.status + def ==(other) + return true if self.same?(other) + self.class == other.class && + id == other.id && + category == other.category && + name == other.name && + photo_urls == other.photo_urls && + tags == other.tags && + status == other.status end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/tag.cr b/samples/client/petstore/crystal/src/petstore/models/tag.cr index 6514d7cf962a..0917d787612b 100644 --- a/samples/client/petstore/crystal/src/petstore/models/tag.cr +++ b/samples/client/petstore/crystal/src/petstore/models/tag.cr @@ -10,12 +10,14 @@ require "big" require "json" +require "yaml" require "time" module Petstore # A tag for a pet class Tag include JSON::Serializable + include YAML::Serializable # Optional properties @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @@ -44,17 +46,17 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - id == o.id && - name == o.name + def ==(other) + return true if self.same?(other) + self.class == other.class && + id == other.id && + name == other.name end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes. diff --git a/samples/client/petstore/crystal/src/petstore/models/user.cr b/samples/client/petstore/crystal/src/petstore/models/user.cr index a70147b19b3b..fb68d42f8649 100644 --- a/samples/client/petstore/crystal/src/petstore/models/user.cr +++ b/samples/client/petstore/crystal/src/petstore/models/user.cr @@ -10,12 +10,14 @@ require "big" require "json" +require "yaml" require "time" module Petstore # A User who is purchasing from the pet store class User include JSON::Serializable + include YAML::Serializable # Optional properties @[JSON::Field(key: "id", type: Int64?, nillable: true, emit_null: false)] @@ -63,23 +65,23 @@ module Petstore # Checks equality by comparing each attribute. # @param [Object] Object to be compared - def ==(o) - return true if self.same?(o) - self.class == o.class && - id == o.id && - username == o.username && - first_name == o.first_name && - last_name == o.last_name && - email == o.email && - password == o.password && - phone == o.phone && - user_status == o.user_status + def ==(other) + return true if self.same?(other) + self.class == other.class && + id == other.id && + username == other.username && + first_name == other.first_name && + last_name == other.last_name && + email == other.email && + password == other.password && + phone == other.phone && + user_status == other.user_status end # @see the `==` method # @param [Object] Object to be compared - def eql?(o) - self == o + def eql?(other) + self == other end # Calculates hash code according to all attributes.