patch_ruby 1.24.2 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Gemfile.lock +9 -10
  4. data/lib/patch_ruby/api/estimates_api.rb +72 -2
  5. data/lib/patch_ruby/api/order_line_items_api.rb +269 -0
  6. data/lib/patch_ruby/api/orders_api.rb +99 -4
  7. data/lib/patch_ruby/api/projects_api.rb +12 -2
  8. data/lib/patch_ruby/api/technology_types_api.rb +7 -2
  9. data/lib/patch_ruby/api_client.rb +3 -3
  10. data/lib/patch_ruby/api_error.rb +2 -2
  11. data/lib/patch_ruby/configuration.rb +3 -4
  12. data/lib/patch_ruby/models/create_air_shipping_estimate_request.rb +2 -2
  13. data/lib/patch_ruby/models/create_bitcoin_estimate_request.rb +2 -2
  14. data/lib/patch_ruby/models/create_ecommerce_estimate_request.rb +2 -2
  15. data/lib/patch_ruby/models/create_ethereum_estimate_request.rb +2 -2
  16. data/lib/patch_ruby/models/create_flight_estimate_request.rb +2 -2
  17. data/lib/patch_ruby/models/create_hotel_estimate_request.rb +2 -2
  18. data/lib/patch_ruby/models/create_mass_estimate_request.rb +7 -7
  19. data/lib/patch_ruby/models/create_order_line_item_request.rb +443 -0
  20. data/lib/patch_ruby/models/create_order_request.rb +79 -70
  21. data/lib/patch_ruby/models/create_rail_shipping_estimate_request.rb +2 -2
  22. data/lib/patch_ruby/models/create_road_shipping_estimate_request.rb +13 -3
  23. data/lib/patch_ruby/models/create_sea_shipping_estimate_request.rb +2 -2
  24. data/lib/patch_ruby/models/create_shipping_estimate_request.rb +2 -2
  25. data/lib/patch_ruby/models/create_success_response.rb +2 -2
  26. data/lib/patch_ruby/models/create_vehicle_estimate_request.rb +2 -2
  27. data/lib/patch_ruby/models/delete_order_line_item_response.rb +257 -0
  28. data/lib/patch_ruby/models/delete_order_response.rb +257 -0
  29. data/lib/patch_ruby/models/disclaimer.rb +282 -0
  30. data/lib/patch_ruby/models/error_response.rb +2 -2
  31. data/lib/patch_ruby/models/estimate.rb +2 -2
  32. data/lib/patch_ruby/models/estimate_list_response.rb +2 -2
  33. data/lib/patch_ruby/models/estimate_response.rb +2 -2
  34. data/lib/patch_ruby/models/highlight.rb +2 -2
  35. data/lib/patch_ruby/models/inventory.rb +33 -3
  36. data/lib/patch_ruby/models/meta_index_object.rb +2 -2
  37. data/lib/patch_ruby/models/order.rb +17 -121
  38. data/lib/patch_ruby/models/order_issued_to.rb +2 -2
  39. data/lib/patch_ruby/models/{order_inventory.rb → order_line_item.rb} +49 -9
  40. data/lib/patch_ruby/models/{order_inventory_project.rb → order_line_item_project.rb} +7 -7
  41. data/lib/patch_ruby/models/{allocation.rb → order_line_item_response.rb} +33 -40
  42. data/lib/patch_ruby/models/order_list_response.rb +2 -2
  43. data/lib/patch_ruby/models/order_response.rb +2 -2
  44. data/lib/patch_ruby/models/parent_technology_type.rb +2 -2
  45. data/lib/patch_ruby/models/photo.rb +2 -2
  46. data/lib/patch_ruby/models/place_order_request.rb +2 -2
  47. data/lib/patch_ruby/models/project.rb +72 -56
  48. data/lib/patch_ruby/models/project_list_response.rb +2 -2
  49. data/lib/patch_ruby/models/project_response.rb +2 -2
  50. data/lib/patch_ruby/models/sdg.rb +2 -2
  51. data/lib/patch_ruby/models/standard.rb +2 -2
  52. data/lib/patch_ruby/models/technology_type.rb +2 -2
  53. data/lib/patch_ruby/models/technology_type_list_response.rb +2 -2
  54. data/lib/patch_ruby/models/update_order_line_item_request.rb +434 -0
  55. data/lib/patch_ruby/version.rb +3 -3
  56. data/lib/patch_ruby.rb +11 -5
  57. data/patch_ruby.gemspec +2 -2
  58. data/spec/api/order_line_items_api_spec.rb +78 -0
  59. data/spec/api_client_spec.rb +2 -2
  60. data/spec/configuration_spec.rb +2 -2
  61. data/spec/factories/create_order_requests.rb +4 -2
  62. data/spec/factories/orders.rb +5 -4
  63. data/spec/factories/projects.rb +1 -4
  64. data/spec/integration/estimates_spec.rb +1 -1
  65. data/spec/integration/orders_spec.rb +121 -44
  66. data/spec/integration/projects_spec.rb +19 -7
  67. data/spec/models/create_order_request_spec.rb +10 -3
  68. data/spec/models/order_spec.rb +8 -23
  69. data/spec/models/project_spec.rb +1 -4
  70. data/spec/spec_helper.rb +2 -2
  71. metadata +35 -31
  72. data/spec/factories/allocations.rb +0 -7
  73. data/spec/models/allocation_spec.rb +0 -59
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -1,9 +1,9 @@
1
1
  =begin
2
- #Patch API V1
2
+ #Patch API V2
3
3
 
4
4
  #The core API used to integrate with Patch's service
5
5
 
6
- The version of the OpenAPI document: v1
6
+ The version of the OpenAPI document: 2
7
7
  Contact: engineering@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
9
  OpenAPI Generator version: 5.3.1
@@ -101,8 +101,8 @@ module Patch
101
101
  invalid_properties.push('invalid value for "mass_g", mass_g cannot be nil.')
102
102
  end
103
103
 
104
- if @mass_g > 100000000000
105
- invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 100000000000.')
104
+ if @mass_g > 100000000000000
105
+ invalid_properties.push('invalid value for "mass_g", must be smaller than or equal to 100000000000000.')
106
106
  end
107
107
 
108
108
  if @mass_g < 0
@@ -116,7 +116,7 @@ module Patch
116
116
  # @return true if the model is valid
117
117
  def valid?
118
118
  return false if @mass_g.nil?
119
- return false if @mass_g > 100000000000
119
+ return false if @mass_g > 100000000000000
120
120
  return false if @mass_g < 0
121
121
  true
122
122
  end
@@ -128,8 +128,8 @@ module Patch
128
128
  fail ArgumentError, 'mass_g cannot be nil'
129
129
  end
130
130
 
131
- if mass_g > 100000000000
132
- fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 100000000000.'
131
+ if mass_g > 100000000000000
132
+ fail ArgumentError, 'invalid value for "mass_g", must be smaller than or equal to 100000000000000.'
133
133
  end
134
134
 
135
135
  if mass_g < 0
@@ -0,0 +1,443 @@
1
+ =begin
2
+ #Patch API V2
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: 2
7
+ Contact: engineering@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Patch
17
+ class CreateOrderLineItemRequest
18
+ attr_accessor :project_id
19
+
20
+ attr_accessor :vintage_year
21
+
22
+ attr_accessor :vintage_start_year
23
+
24
+ attr_accessor :vintage_end_year
25
+
26
+ attr_accessor :price
27
+
28
+ attr_accessor :currency
29
+
30
+ attr_accessor :amount
31
+
32
+ attr_accessor :unit
33
+
34
+ class EnumAttributeValidator
35
+ attr_reader :datatype
36
+ attr_reader :allowable_values
37
+
38
+ def initialize(datatype, allowable_values)
39
+ @allowable_values = allowable_values.map do |value|
40
+ case datatype.to_s
41
+ when /Integer/i
42
+ value.to_i
43
+ when /Float/i
44
+ value.to_f
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+
51
+ def valid?(value)
52
+ !value || allowable_values.include?(value)
53
+ end
54
+ end
55
+
56
+ # Attribute mapping from ruby-style variable name to JSON key.
57
+ def self.attribute_map
58
+ {
59
+ :'project_id' => :'project_id',
60
+ :'vintage_year' => :'vintage_year',
61
+ :'vintage_start_year' => :'vintage_start_year',
62
+ :'vintage_end_year' => :'vintage_end_year',
63
+ :'price' => :'price',
64
+ :'currency' => :'currency',
65
+ :'amount' => :'amount',
66
+ :'unit' => :'unit'
67
+ }
68
+ end
69
+
70
+ # Returns all the JSON keys this model knows about
71
+ def self.acceptable_attributes
72
+ attribute_map.values
73
+ end
74
+
75
+ # Attribute type mapping.
76
+ def self.openapi_types
77
+ {
78
+ :'project_id' => :'String',
79
+ :'vintage_year' => :'Integer',
80
+ :'vintage_start_year' => :'Integer',
81
+ :'vintage_end_year' => :'Integer',
82
+ :'price' => :'Integer',
83
+ :'currency' => :'String',
84
+ :'amount' => :'Integer',
85
+ :'unit' => :'String'
86
+ }
87
+ end
88
+
89
+ # List of attributes with nullable: true
90
+ def self.openapi_nullable
91
+ Set.new([
92
+ :'vintage_year',
93
+ :'vintage_start_year',
94
+ :'vintage_end_year',
95
+ :'price',
96
+ :'currency',
97
+ :'amount',
98
+ :'unit'
99
+ ])
100
+ end
101
+
102
+
103
+ # Allows models with corresponding API classes to delegate API operations to those API classes
104
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
105
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
106
+ def self.method_missing(message, *args, &block)
107
+ if Object.const_defined?('Patch::CreateOrderLineItemRequestsApi::OPERATIONS') && Patch::CreateOrderLineItemRequestsApi::OPERATIONS.include?(message)
108
+ Patch::CreateOrderLineItemRequestsApi.new.send(message, *args)
109
+ else
110
+ super
111
+ end
112
+ end
113
+
114
+ # Initializes the object
115
+ # @param [Hash] attributes Model attributes in the form of hash
116
+ def initialize(attributes = {})
117
+ if (!attributes.is_a?(Hash))
118
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateOrderLineItemRequest` initialize method"
119
+ end
120
+
121
+ # check to see if the attribute exists and convert string to symbol for hash key
122
+ attributes = attributes.each_with_object({}) { |(k, v), h|
123
+ if (!self.class.attribute_map.key?(k.to_sym))
124
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateOrderLineItemRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
125
+ end
126
+ h[k.to_sym] = v
127
+ }
128
+
129
+ if attributes.key?(:'project_id')
130
+ self.project_id = attributes[:'project_id']
131
+ end
132
+
133
+ if attributes.key?(:'vintage_year')
134
+ self.vintage_year = attributes[:'vintage_year']
135
+ end
136
+
137
+ if attributes.key?(:'vintage_start_year')
138
+ self.vintage_start_year = attributes[:'vintage_start_year']
139
+ end
140
+
141
+ if attributes.key?(:'vintage_end_year')
142
+ self.vintage_end_year = attributes[:'vintage_end_year']
143
+ end
144
+
145
+ if attributes.key?(:'price')
146
+ self.price = attributes[:'price']
147
+ end
148
+
149
+ if attributes.key?(:'currency')
150
+ self.currency = attributes[:'currency']
151
+ end
152
+
153
+ if attributes.key?(:'amount')
154
+ self.amount = attributes[:'amount']
155
+ end
156
+
157
+ if attributes.key?(:'unit')
158
+ self.unit = attributes[:'unit']
159
+ end
160
+ end
161
+
162
+ # Show invalid properties with the reasons. Usually used together with valid?
163
+ # @return Array for valid properties with the reasons
164
+ def list_invalid_properties
165
+ invalid_properties = Array.new
166
+ if !@vintage_year.nil? && @vintage_year > 2100
167
+ invalid_properties.push('invalid value for "vintage_year", must be smaller than or equal to 2100.')
168
+ end
169
+
170
+ if !@vintage_year.nil? && @vintage_year < 1900
171
+ invalid_properties.push('invalid value for "vintage_year", must be greater than or equal to 1900.')
172
+ end
173
+
174
+ if !@vintage_start_year.nil? && @vintage_start_year > 2100
175
+ invalid_properties.push('invalid value for "vintage_start_year", must be smaller than or equal to 2100.')
176
+ end
177
+
178
+ if !@vintage_start_year.nil? && @vintage_start_year < 1900
179
+ invalid_properties.push('invalid value for "vintage_start_year", must be greater than or equal to 1900.')
180
+ end
181
+
182
+ if !@vintage_end_year.nil? && @vintage_end_year > 2100
183
+ invalid_properties.push('invalid value for "vintage_end_year", must be smaller than or equal to 2100.')
184
+ end
185
+
186
+ if !@vintage_end_year.nil? && @vintage_end_year < 1900
187
+ invalid_properties.push('invalid value for "vintage_end_year", must be greater than or equal to 1900.')
188
+ end
189
+
190
+ if !@price.nil? && @price < 2
191
+ invalid_properties.push('invalid value for "price", must be greater than or equal to 2.')
192
+ end
193
+
194
+ if !@amount.nil? && @amount > 100000000000000
195
+ invalid_properties.push('invalid value for "amount", must be smaller than or equal to 100000000000000.')
196
+ end
197
+
198
+ if !@amount.nil? && @amount < 0
199
+ invalid_properties.push('invalid value for "amount", must be greater than or equal to 0.')
200
+ end
201
+
202
+ invalid_properties
203
+ end
204
+
205
+ # Check to see if the all the properties in the model are valid
206
+ # @return true if the model is valid
207
+ def valid?
208
+ return false if !@vintage_year.nil? && @vintage_year > 2100
209
+ return false if !@vintage_year.nil? && @vintage_year < 1900
210
+ return false if !@vintage_start_year.nil? && @vintage_start_year > 2100
211
+ return false if !@vintage_start_year.nil? && @vintage_start_year < 1900
212
+ return false if !@vintage_end_year.nil? && @vintage_end_year > 2100
213
+ return false if !@vintage_end_year.nil? && @vintage_end_year < 1900
214
+ return false if !@price.nil? && @price < 2
215
+ return false if !@amount.nil? && @amount > 100000000000000
216
+ return false if !@amount.nil? && @amount < 0
217
+ unit_validator = EnumAttributeValidator.new('String', ["g", "Wh"])
218
+ return false unless unit_validator.valid?(@unit)
219
+ true
220
+ end
221
+
222
+ # Custom attribute writer method with validation
223
+ # @param [Object] vintage_year Value to be assigned
224
+ def vintage_year=(vintage_year)
225
+ if !vintage_year.nil? && vintage_year > 2100
226
+ fail ArgumentError, 'invalid value for "vintage_year", must be smaller than or equal to 2100.'
227
+ end
228
+
229
+ if !vintage_year.nil? && vintage_year < 1900
230
+ fail ArgumentError, 'invalid value for "vintage_year", must be greater than or equal to 1900.'
231
+ end
232
+
233
+ @vintage_year = vintage_year
234
+ end
235
+
236
+ # Custom attribute writer method with validation
237
+ # @param [Object] vintage_start_year Value to be assigned
238
+ def vintage_start_year=(vintage_start_year)
239
+ if !vintage_start_year.nil? && vintage_start_year > 2100
240
+ fail ArgumentError, 'invalid value for "vintage_start_year", must be smaller than or equal to 2100.'
241
+ end
242
+
243
+ if !vintage_start_year.nil? && vintage_start_year < 1900
244
+ fail ArgumentError, 'invalid value for "vintage_start_year", must be greater than or equal to 1900.'
245
+ end
246
+
247
+ @vintage_start_year = vintage_start_year
248
+ end
249
+
250
+ # Custom attribute writer method with validation
251
+ # @param [Object] vintage_end_year Value to be assigned
252
+ def vintage_end_year=(vintage_end_year)
253
+ if !vintage_end_year.nil? && vintage_end_year > 2100
254
+ fail ArgumentError, 'invalid value for "vintage_end_year", must be smaller than or equal to 2100.'
255
+ end
256
+
257
+ if !vintage_end_year.nil? && vintage_end_year < 1900
258
+ fail ArgumentError, 'invalid value for "vintage_end_year", must be greater than or equal to 1900.'
259
+ end
260
+
261
+ @vintage_end_year = vintage_end_year
262
+ end
263
+
264
+ # Custom attribute writer method with validation
265
+ # @param [Object] price Value to be assigned
266
+ def price=(price)
267
+ if !price.nil? && price < 2
268
+ fail ArgumentError, 'invalid value for "price", must be greater than or equal to 2.'
269
+ end
270
+
271
+ @price = price
272
+ end
273
+
274
+ # Custom attribute writer method with validation
275
+ # @param [Object] amount Value to be assigned
276
+ def amount=(amount)
277
+ if !amount.nil? && amount > 100000000000000
278
+ fail ArgumentError, 'invalid value for "amount", must be smaller than or equal to 100000000000000.'
279
+ end
280
+
281
+ if !amount.nil? && amount < 0
282
+ fail ArgumentError, 'invalid value for "amount", must be greater than or equal to 0.'
283
+ end
284
+
285
+ @amount = amount
286
+ end
287
+
288
+ # Custom attribute writer method checking allowed values (enum).
289
+ # @param [Object] unit Object to be assigned
290
+ def unit=(unit)
291
+ validator = EnumAttributeValidator.new('String', ["g", "Wh"])
292
+ unless validator.valid?(unit)
293
+ fail ArgumentError, "invalid value for \"unit\", must be one of #{validator.allowable_values}."
294
+ end
295
+ @unit = unit
296
+ end
297
+
298
+ # Checks equality by comparing each attribute.
299
+ # @param [Object] Object to be compared
300
+ def ==(o)
301
+ return true if self.equal?(o)
302
+ self.class == o.class &&
303
+ project_id == o.project_id &&
304
+ vintage_year == o.vintage_year &&
305
+ vintage_start_year == o.vintage_start_year &&
306
+ vintage_end_year == o.vintage_end_year &&
307
+ price == o.price &&
308
+ currency == o.currency &&
309
+ amount == o.amount &&
310
+ unit == o.unit
311
+ end
312
+
313
+ # @see the `==` method
314
+ # @param [Object] Object to be compared
315
+ def eql?(o)
316
+ self == o
317
+ end
318
+
319
+ # Calculates hash code according to all attributes.
320
+ # @return [Integer] Hash code
321
+ def hash
322
+ [project_id, vintage_year, vintage_start_year, vintage_end_year, price, currency, amount, unit].hash
323
+ end
324
+
325
+ # Builds the object from hash
326
+ # @param [Hash] attributes Model attributes in the form of hash
327
+ # @return [Object] Returns the model itself
328
+ def self.build_from_hash(attributes)
329
+ new.build_from_hash(attributes)
330
+ end
331
+
332
+ # Builds the object from hash
333
+ # @param [Hash] attributes Model attributes in the form of hash
334
+ # @return [Object] Returns the model itself
335
+ def build_from_hash(attributes)
336
+ return nil unless attributes.is_a?(Hash)
337
+ self.class.openapi_types.each_pair do |key, type|
338
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
339
+ self.send("#{key}=", nil)
340
+ elsif type =~ /\AArray<(.*)>/i
341
+ # check to ensure the input is an array given that the attribute
342
+ # is documented as an array but the input is not
343
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
344
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
345
+ end
346
+ elsif !attributes[self.class.attribute_map[key]].nil?
347
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
348
+ end
349
+ end
350
+
351
+ self
352
+ end
353
+
354
+ # Deserializes the data based on type
355
+ # @param string type Data type
356
+ # @param string value Value to be deserialized
357
+ # @return [Object] Deserialized data
358
+ def _deserialize(type, value)
359
+ case type.to_sym
360
+ when :Time
361
+ Time.parse(value)
362
+ when :Date
363
+ Date.parse(value)
364
+ when :String
365
+ value.to_s
366
+ when :Integer
367
+ value.to_i
368
+ when :Float
369
+ value.to_f
370
+ when :Boolean
371
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
372
+ true
373
+ else
374
+ false
375
+ end
376
+ when :Object
377
+ # generic object (usually a Hash), return directly
378
+ value
379
+ when /\AArray<(?<inner_type>.+)>\z/
380
+ inner_type = Regexp.last_match[:inner_type]
381
+ value.map { |v| _deserialize(inner_type, v) }
382
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
383
+ k_type = Regexp.last_match[:k_type]
384
+ v_type = Regexp.last_match[:v_type]
385
+ {}.tap do |hash|
386
+ value.each do |k, v|
387
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
388
+ end
389
+ end
390
+ else # model
391
+ # models (e.g. Pet) or oneOf
392
+ klass = Patch.const_get(type)
393
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
394
+ end
395
+ end
396
+
397
+ # Returns the string representation of the object
398
+ # @return [String] String presentation of the object
399
+ def to_s
400
+ to_hash.to_s
401
+ end
402
+
403
+ # to_body is an alias to to_hash (backward compatibility)
404
+ # @return [Hash] Returns the object in the form of hash
405
+ def to_body
406
+ to_hash
407
+ end
408
+
409
+ # Returns the object in the form of hash
410
+ # @return [Hash] Returns the object in the form of hash
411
+ def to_hash
412
+ hash = {}
413
+ self.class.attribute_map.each_pair do |attr, param|
414
+ value = self.send(attr)
415
+ if value.nil?
416
+ is_nullable = self.class.openapi_nullable.include?(attr)
417
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
418
+ end
419
+
420
+ hash[param] = _to_hash(value)
421
+ end
422
+ hash
423
+ end
424
+
425
+ # Outputs non-array value in the form of hash
426
+ # For object, use to_hash. Otherwise, just return the value
427
+ # @param [Object] value Any valid value
428
+ # @return [Hash] Returns the value in the form of hash
429
+ def _to_hash(value)
430
+ if value.is_a?(Array)
431
+ value.compact.map { |v| _to_hash(v) }
432
+ elsif value.is_a?(Hash)
433
+ {}.tap do |hash|
434
+ value.each { |k, v| hash[k] = _to_hash(v) }
435
+ end
436
+ elsif value.respond_to? :to_hash
437
+ value.to_hash
438
+ else
439
+ value
440
+ end
441
+ end
442
+ end
443
+ end