From a3de18407b3e455284d357c1b65cbd4faacfec06 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Fri, 29 Jul 2022 14:42:55 -0700 Subject: [PATCH] Fix the generator for optional body parameters (#69) * Try again * Change * Whatever * Generate the right way --- Gemfile.lock | 2 +- lib/patch_ruby.rb | 3 +- lib/patch_ruby/api/estimates_api.rb | 22 +- lib/patch_ruby/api/orders_api.rb | 70 ++--- lib/patch_ruby/api/projects_api.rb | 4 +- lib/patch_ruby/api_client.rb | 2 +- lib/patch_ruby/models/create_order_request.rb | 3 +- lib/patch_ruby/models/order.rb | 6 +- .../{issued_to.rb => order_issued_to.rb} | 14 +- lib/patch_ruby/models/place_order_request.rb | 3 +- lib/patch_ruby/models/v1_orders_issued_to.rb | 239 ------------------ lib/patch_ruby/version.rb | 2 +- spec/models/create_order_request_spec.rb | 2 +- 13 files changed, 68 insertions(+), 304 deletions(-) rename lib/patch_ruby/models/{issued_to.rb => order_issued_to.rb} (93%) delete mode 100644 lib/patch_ruby/models/v1_orders_issued_to.rb diff --git a/Gemfile.lock b/Gemfile.lock index 4b8c239..8713add 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - patch_ruby (1.24.0) + patch_ruby (1.24.1) typhoeus (~> 1.0, >= 1.0.1) GEM diff --git a/lib/patch_ruby.rb b/lib/patch_ruby.rb index bc6badc..1364195 100644 --- a/lib/patch_ruby.rb +++ b/lib/patch_ruby.rb @@ -37,11 +37,11 @@ require 'patch_ruby/models/estimate_response' require 'patch_ruby/models/highlight' require 'patch_ruby/models/inventory' -require 'patch_ruby/models/issued_to' require 'patch_ruby/models/meta_index_object' require 'patch_ruby/models/order' require 'patch_ruby/models/order_inventory' require 'patch_ruby/models/order_inventory_project' +require 'patch_ruby/models/order_issued_to' require 'patch_ruby/models/order_list_response' require 'patch_ruby/models/order_response' require 'patch_ruby/models/parent_technology_type' @@ -54,7 +54,6 @@ require 'patch_ruby/models/standard' require 'patch_ruby/models/technology_type' require 'patch_ruby/models/technology_type_list_response' -require 'patch_ruby/models/v1_orders_issued_to' # APIs require 'patch_ruby/api/estimates_api' diff --git a/lib/patch_ruby/api/estimates_api.rb b/lib/patch_ruby/api/estimates_api.rb index 967c30f..7569368 100644 --- a/lib/patch_ruby/api/estimates_api.rb +++ b/lib/patch_ruby/api/estimates_api.rb @@ -47,7 +47,7 @@ def create_air_shipping_estimate(create_air_shipping_estimate_request = {}, opts end # Creates a GLEC air shipping estimate given freight mass and logistics - # Creates a GLEC air shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates a GLEC air shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_air_shipping_estimate_request [CreateAirShippingEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -116,7 +116,7 @@ def create_bitcoin_estimate(create_bitcoin_estimate_request = {}, opts = {}) end # Create a bitcoin estimate given a timestamp and transaction value - # Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_bitcoin_estimate_request [CreateBitcoinEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -185,7 +185,7 @@ def create_ethereum_estimate(create_ethereum_estimate_request = {}, opts = {}) end # Create an ethereum estimate - # Creates an ethereum estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates an ethereum estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_ethereum_estimate_request [CreateEthereumEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -254,7 +254,7 @@ def create_flight_estimate(create_flight_estimate_request = {}, opts = {}) end # Create a flight estimate given the distance traveled in meters - # Creates a flight estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates a flight estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_flight_estimate_request [CreateFlightEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -323,7 +323,7 @@ def create_hotel_estimate(create_hotel_estimate_request = {}, opts = {}) end # Create a hotel estimate. - # Creates a hotel estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. + # Creates a hotel estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. # @param create_hotel_estimate_request [CreateHotelEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -392,7 +392,7 @@ def create_mass_estimate(create_mass_estimate_request = {}, opts = {}) end # Create an estimate based on mass of CO2 - # Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, linked to the estimate. + # Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, linked to the estimate. # @param create_mass_estimate_request [CreateMassEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -461,7 +461,7 @@ def create_rail_shipping_estimate(create_rail_shipping_estimate_request = {}, op end # Creates a GLEC rail shipping estimate given freight mass and logistics - # Creates a GLEC rail shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates a GLEC rail shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_rail_shipping_estimate_request [CreateRailShippingEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -530,7 +530,7 @@ def create_road_shipping_estimate(create_road_shipping_estimate_request = {}, op end # Creates a GLEC road shipping estimate given freight mass and logistics - # Creates a GLEC road shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates a GLEC road shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_road_shipping_estimate_request [CreateRoadShippingEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -599,7 +599,7 @@ def create_sea_shipping_estimate(create_sea_shipping_estimate_request = {}, opts end # Creates a GLEC sea shipping estimate given freight mass and logistics - # Creates a GLEC sea shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates a GLEC sea shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_sea_shipping_estimate_request [CreateSeaShippingEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -668,7 +668,7 @@ def create_shipping_estimate(create_shipping_estimate_request = {}, opts = {}) end # Create a shipping estimate given the distance traveled in meters, package weight, and transportation method. - # Creates a shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. + # Creates a shipping estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. # @param create_shipping_estimate_request [CreateShippingEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers @@ -737,7 +737,7 @@ def create_vehicle_estimate(create_vehicle_estimate_request = {}, opts = {}) end # Create a vehicle estimate given the distance traveled in meters and the type of vehicle - # Creates an estimate and calculates the amount of CO2 to be compensated depending on the distance and the vehicle. An order in the `draft` state may be created based on the parameters, linked to the estimate. + # Creates an estimate and calculates the amount of CO2 to be compensated depending on the distance and the vehicle. An order in the `draft` state may be created based on the parameters, linked to the estimate. # @param create_vehicle_estimate_request [CreateVehicleEstimateRequest] # @param [Hash] opts the optional parameters # @return [Array<(EstimateResponse, Integer, Hash)>] EstimateResponse data, response status code and response headers diff --git a/lib/patch_ruby/api/orders_api.rb b/lib/patch_ruby/api/orders_api.rb index 24fa802..233f033 100644 --- a/lib/patch_ruby/api/orders_api.rb +++ b/lib/patch_ruby/api/orders_api.rb @@ -28,18 +28,19 @@ def initialize(api_client = ApiClient.default) @api_client = api_client end # Cancel an order - # Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled. - # @param id [String] + # Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled. + # @param id [String] # @param [Hash] opts the optional parameters # @return [OrderResponse] def cancel_order(id, opts = {}) + data, _status_code, _headers = cancel_order_with_http_info(id, opts) data end # Cancel an order - # Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled. - # @param id [String] + # Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` or `placed` state can be cancelled. + # @param id [String] # @param [Hash] opts the optional parameters # @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers def cancel_order_with_http_info(id, opts = {}) @@ -91,19 +92,19 @@ def cancel_order_with_http_info(id, opts = {}) end # Creates an order - # Creates an order in the `placed` or `draft` state. - # @param create_order_request [CreateOrderRequest] + # Creates an order in the `placed` or `draft` state. + # @param create_order_request [CreateOrderRequest] # @param [Hash] opts the optional parameters # @return [OrderResponse] def create_order(create_order_request = {}, opts = {}) - _create_order_request = Patch::CreateOrderRequest.new(create_order_request) + _create_order_request = Patch::CreateOrderRequest.new(create_order_request) data, _status_code, _headers = create_order_with_http_info(_create_order_request, opts) data end # Creates an order - # Creates an order in the `placed` or `draft` state. - # @param create_order_request [CreateOrderRequest] + # Creates an order in the `placed` or `draft` state. + # @param create_order_request [CreateOrderRequest] # @param [Hash] opts the optional parameters # @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers def create_order_with_http_info(create_order_request, opts = {}) @@ -160,23 +161,22 @@ def create_order_with_http_info(create_order_request, opts = {}) end # Place an order - # Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed - # @param id [String] + # Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed + # @param id [String] # @param [Hash] opts the optional parameters - # @option opts [PlaceOrderRequest] :place_order_request + # @option opts [PlaceOrderRequest] :place_order_request # @return [OrderResponse] - def place_order(order_id, opts = {}) - place_order_request = Patch::PlaceOrderRequest.new(opts) - opts[:place_order_request] = place_order_request - data, _status_code, _headers = place_order_with_http_info(order_id, opts) + def place_order(id, opts = {}) + + data, _status_code, _headers = place_order_with_http_info(id, opts) data end # Place an order - # Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed - # @param id [String] + # Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed + # @param id [String] # @param [Hash] opts the optional parameters - # @option opts [PlaceOrderRequest] :place_order_request + # @option opts [PlaceOrderRequest] :place_order_request # @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers def place_order_with_http_info(id, opts = {}) if @api_client.config.debugging @@ -206,7 +206,7 @@ def place_order_with_http_info(id, opts = {}) form_params = opts[:form_params] || {} # http body (model) - post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'place_order_request']) + post_body = opts[:debug_body] || @api_client.object_to_http_body(opts) # return_type return_type = opts[:debug_return_type] || 'OrderResponse' @@ -232,18 +232,19 @@ def place_order_with_http_info(id, opts = {}) end # Retrieves an order - # Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. - # @param id [String] + # Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. + # @param id [String] # @param [Hash] opts the optional parameters # @return [OrderResponse] def retrieve_order(id, opts = {}) + data, _status_code, _headers = retrieve_order_with_http_info(id, opts) data end # Retrieves an order - # Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. - # @param id [String] + # Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. + # @param id [String] # @param [Hash] opts the optional parameters # @return [Array<(OrderResponse, Integer, Hash)>] OrderResponse data, response status code and response headers def retrieve_order_with_http_info(id, opts = {}) @@ -295,25 +296,26 @@ def retrieve_order_with_http_info(id, opts = {}) end # Retrieves a list of orders - # Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. + # Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # @param [Hash] opts the optional parameters - # @option opts [Integer] :page - # @option opts [String] :metadata - # @option opts [String] :metadata_example1 - # @option opts [String] :metadata_example2 + # @option opts [Integer] :page + # @option opts [String] :metadata + # @option opts [String] :metadata_example1 + # @option opts [String] :metadata_example2 # @return [OrderListResponse] def retrieve_orders(opts = {}) + data, _status_code, _headers = retrieve_orders_with_http_info(opts) data end # Retrieves a list of orders - # Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. + # Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # @param [Hash] opts the optional parameters - # @option opts [Integer] :page - # @option opts [String] :metadata - # @option opts [String] :metadata_example1 - # @option opts [String] :metadata_example2 + # @option opts [Integer] :page + # @option opts [String] :metadata + # @option opts [String] :metadata_example1 + # @option opts [String] :metadata_example2 # @return [Array<(OrderListResponse, Integer, Hash)>] OrderListResponse data, response status code and response headers def retrieve_orders_with_http_info(opts = {}) if @api_client.config.debugging diff --git a/lib/patch_ruby/api/projects_api.rb b/lib/patch_ruby/api/projects_api.rb index d597620..982a13b 100644 --- a/lib/patch_ruby/api/projects_api.rb +++ b/lib/patch_ruby/api/projects_api.rb @@ -37,7 +37,7 @@ def retrieve_project(id, opts = {}) end # Retrieves a project - # Retrieves a project available on Patch's platform. + # Retrieves a project available on Patch's platform. # @param id [String] # @param [Hash] opts the optional parameters # @option opts [String] :accept_language @@ -107,7 +107,7 @@ def retrieve_projects(opts = {}) end # Retrieves a list of projects - # Retrieves a list of projects available for purchase on Patch's platform. + # Retrieves a list of projects available for purchase on Patch's platform. # @param [Hash] opts the optional parameters # @option opts [Integer] :page # @option opts [String] :country diff --git a/lib/patch_ruby/api_client.rb b/lib/patch_ruby/api_client.rb index f721a91..3a8ff83 100644 --- a/lib/patch_ruby/api_client.rb +++ b/lib/patch_ruby/api_client.rb @@ -31,7 +31,7 @@ class ApiClient # @option config [Configuration] Configuration for initializing the object, default to Configuration.default def initialize(config = Configuration.default) @config = config - @user_agent = "patch-ruby/1.24.0" + @user_agent = "patch-ruby/1.24.1" @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent diff --git a/lib/patch_ruby/models/create_order_request.rb b/lib/patch_ruby/models/create_order_request.rb index 594bc0b..aefc04d 100644 --- a/lib/patch_ruby/models/create_order_request.rb +++ b/lib/patch_ruby/models/create_order_request.rb @@ -94,7 +94,7 @@ def self.openapi_types :'currency' => :'String', :'amount' => :'Integer', :'unit' => :'String', - :'issued_to' => :'V1OrdersIssuedTo' + :'issued_to' => :'OrderIssuedTo' } end @@ -111,7 +111,6 @@ def self.openapi_nullable :'currency', :'amount', :'unit', - :'issued_to' ]) end diff --git a/lib/patch_ruby/models/order.rb b/lib/patch_ruby/models/order.rb index 48088be..addab63 100644 --- a/lib/patch_ruby/models/order.rb +++ b/lib/patch_ruby/models/order.rb @@ -66,6 +66,7 @@ class Order # An array containing the inventory allocated for this order. Inventory is grouped by project, vintage year, and price. attr_accessor :inventory + # An object containing the name & email of the party the inventory will be issued to. attr_accessor :issued_to class EnumAttributeValidator @@ -139,7 +140,7 @@ def self.openapi_types :'registry_url' => :'String', :'metadata' => :'Object', :'inventory' => :'Array', - :'issued_to' => :'IssuedTo' + :'issued_to' => :'OrderIssuedTo' } end @@ -251,6 +252,9 @@ def initialize(attributes = {}) end if attributes.key?(:'issued_to') + if (value = attributes[:'issued_to']).is_a?(Hash) + self.issued_to = value + end self.issued_to = attributes[:'issued_to'] end end diff --git a/lib/patch_ruby/models/issued_to.rb b/lib/patch_ruby/models/order_issued_to.rb similarity index 93% rename from lib/patch_ruby/models/issued_to.rb rename to lib/patch_ruby/models/order_issued_to.rb index c3470cd..8955de6 100644 --- a/lib/patch_ruby/models/issued_to.rb +++ b/lib/patch_ruby/models/order_issued_to.rb @@ -15,11 +15,11 @@ module Patch # An object containing the name & email of the party the inventory will be issued to. - class IssuedTo - # Name provided for the issuee + class OrderIssuedTo + # The name of the issuee attr_accessor :name - # Email address provided for the issuee + # The email address of the issuee attr_accessor :email # Attribute mapping from ruby-style variable name to JSON key. @@ -56,8 +56,8 @@ def self.openapi_nullable # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id # Eg. Order.create_order delegates to OrdersApi.new.create_order def self.method_missing(message, *args, &block) - if Object.const_defined?('Patch::IssuedTosApi::OPERATIONS') && Patch::IssuedTosApi::OPERATIONS.include?(message) - Patch::IssuedTosApi.new.send(message, *args) + if Object.const_defined?('Patch::OrderIssuedTosApi::OPERATIONS') && Patch::OrderIssuedTosApi::OPERATIONS.include?(message) + Patch::OrderIssuedTosApi.new.send(message, *args) else super end @@ -67,13 +67,13 @@ def self.method_missing(message, *args, &block) # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) if (!attributes.is_a?(Hash)) - fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::IssuedTo` initialize method" + fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::OrderIssuedTo` initialize method" end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| if (!self.class.attribute_map.key?(k.to_sym)) - fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::IssuedTo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect + fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::OrderIssuedTo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect end h[k.to_sym] = v } diff --git a/lib/patch_ruby/models/place_order_request.rb b/lib/patch_ruby/models/place_order_request.rb index 9dc25bc..2f914a3 100644 --- a/lib/patch_ruby/models/place_order_request.rb +++ b/lib/patch_ruby/models/place_order_request.rb @@ -32,14 +32,13 @@ def self.acceptable_attributes # Attribute type mapping. def self.openapi_types { - :'issued_to' => :'V1OrdersIssuedTo' + :'issued_to' => :'OrderIssuedTo' } end # List of attributes with nullable: true def self.openapi_nullable Set.new([ - :'issued_to' ]) end diff --git a/lib/patch_ruby/models/v1_orders_issued_to.rb b/lib/patch_ruby/models/v1_orders_issued_to.rb deleted file mode 100644 index 0e5f0f7..0000000 --- a/lib/patch_ruby/models/v1_orders_issued_to.rb +++ /dev/null @@ -1,239 +0,0 @@ -=begin -#Patch API V1 - -#The core API used to integrate with Patch's service - -The version of the OpenAPI document: v1 -Contact: engineering@usepatch.com -Generated by: https://openapi-generator.tech -OpenAPI Generator version: 5.3.1 - -=end - -require 'date' -require 'time' - -module Patch - class V1OrdersIssuedTo - attr_accessor :email - - attr_accessor :name - - # Attribute mapping from ruby-style variable name to JSON key. - def self.attribute_map - { - :'email' => :'email', - :'name' => :'name' - } - end - - # Returns all the JSON keys this model knows about - def self.acceptable_attributes - attribute_map.values - end - - # Attribute type mapping. - def self.openapi_types - { - :'email' => :'String', - :'name' => :'String' - } - end - - # List of attributes with nullable: true - def self.openapi_nullable - Set.new([ - :'email', - :'name' - ]) - end - - - # Allows models with corresponding API classes to delegate API operations to those API classes - # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id - # Eg. Order.create_order delegates to OrdersApi.new.create_order - def self.method_missing(message, *args, &block) - if Object.const_defined?('Patch::V1OrdersIssuedTosApi::OPERATIONS') && Patch::V1OrdersIssuedTosApi::OPERATIONS.include?(message) - Patch::V1OrdersIssuedTosApi.new.send(message, *args) - else - super - end - end - - # Initializes the object - # @param [Hash] attributes Model attributes in the form of hash - def initialize(attributes = {}) - if (!attributes.is_a?(Hash)) - fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::V1OrdersIssuedTo` initialize method" - end - - # check to see if the attribute exists and convert string to symbol for hash key - attributes = attributes.each_with_object({}) { |(k, v), h| - if (!self.class.attribute_map.key?(k.to_sym)) - fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::V1OrdersIssuedTo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect - end - h[k.to_sym] = v - } - - if attributes.key?(:'email') - self.email = attributes[:'email'] - end - - if attributes.key?(:'name') - self.name = attributes[:'name'] - end - end - - # Show invalid properties with the reasons. Usually used together with valid? - # @return Array for valid properties with the reasons - def list_invalid_properties - invalid_properties = Array.new - invalid_properties - end - - # Check to see if the all the properties in the model are valid - # @return true if the model is valid - def valid? - true - end - - # Checks equality by comparing each attribute. - # @param [Object] Object to be compared - def ==(o) - return true if self.equal?(o) - self.class == o.class && - email == o.email && - name == o.name - end - - # @see the `==` method - # @param [Object] Object to be compared - def eql?(o) - self == o - end - - # Calculates hash code according to all attributes. - # @return [Integer] Hash code - def hash - [email, name].hash - end - - # Builds the object from hash - # @param [Hash] attributes Model attributes in the form of hash - # @return [Object] Returns the model itself - def self.build_from_hash(attributes) - new.build_from_hash(attributes) - end - - # Builds the object from hash - # @param [Hash] attributes Model attributes in the form of hash - # @return [Object] Returns the model itself - def build_from_hash(attributes) - return nil unless attributes.is_a?(Hash) - self.class.openapi_types.each_pair do |key, type| - if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key) - self.send("#{key}=", nil) - elsif type =~ /\AArray<(.*)>/i - # check to ensure the input is an array given that the attribute - # is documented as an array but the input is not - if attributes[self.class.attribute_map[key]].is_a?(Array) - self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) - end - elsif !attributes[self.class.attribute_map[key]].nil? - self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) - end - end - - self - end - - # Deserializes the data based on type - # @param string type Data type - # @param string value Value to be deserialized - # @return [Object] Deserialized data - def _deserialize(type, value) - case type.to_sym - when :Time - Time.parse(value) - when :Date - Date.parse(value) - when :String - value.to_s - when :Integer - value.to_i - when :Float - value.to_f - when :Boolean - if value.to_s =~ /\A(true|t|yes|y|1)\z/i - true - else - false - end - when :Object - # generic object (usually a Hash), return directly - value - when /\AArray<(?.+)>\z/ - inner_type = Regexp.last_match[:inner_type] - value.map { |v| _deserialize(inner_type, v) } - when /\AHash<(?.+?), (?.+)>\z/ - k_type = Regexp.last_match[:k_type] - v_type = Regexp.last_match[:v_type] - {}.tap do |hash| - value.each do |k, v| - hash[_deserialize(k_type, k)] = _deserialize(v_type, v) - end - end - else # model - # models (e.g. Pet) or oneOf - klass = Patch.const_get(type) - klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value) - end - end - - # Returns the string representation of the object - # @return [String] String presentation of the object - def to_s - to_hash.to_s - end - - # to_body is an alias to to_hash (backward compatibility) - # @return [Hash] Returns the object in the form of hash - def to_body - to_hash - end - - # Returns the object in the form of hash - # @return [Hash] Returns the object in the form of hash - def to_hash - hash = {} - self.class.attribute_map.each_pair do |attr, param| - value = self.send(attr) - if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) - next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) - end - - hash[param] = _to_hash(value) - end - hash - end - - # Outputs non-array value in the form of hash - # For object, use to_hash. Otherwise, just return the value - # @param [Object] value Any valid value - # @return [Hash] Returns the value in the form of hash - def _to_hash(value) - if value.is_a?(Array) - value.compact.map { |v| _to_hash(v) } - elsif value.is_a?(Hash) - {}.tap do |hash| - value.each { |k, v| hash[k] = _to_hash(v) } - end - elsif value.respond_to? :to_hash - value.to_hash - else - value - end - end - end -end diff --git a/lib/patch_ruby/version.rb b/lib/patch_ruby/version.rb index 047401f..76436f8 100644 --- a/lib/patch_ruby/version.rb +++ b/lib/patch_ruby/version.rb @@ -11,5 +11,5 @@ =end module Patch - VERSION = '1.24.0' + VERSION = '1.24.1' end diff --git a/spec/models/create_order_request_spec.rb b/spec/models/create_order_request_spec.rb index 9d38471..a182190 100644 --- a/spec/models/create_order_request_spec.rb +++ b/spec/models/create_order_request_spec.rb @@ -31,7 +31,7 @@ let(:instance) { @instance } let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, total_price_cents_usd: @instance.total_price_cents_usd, metadata: @instance.metadata } } let(:nullable_properties) do - Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit issued_to]) + Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit]) end end