patch_ruby 1.23.0 → 1.24.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,16 +14,47 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module Patch
17
- class V1OrdersIssuedTo
18
- attr_accessor :email
17
+ class CreateEcommerceEstimateRequest
18
+ attr_accessor :distance_m
19
19
 
20
- attr_accessor :name
20
+ attr_accessor :package_mass_g
21
+
22
+ attr_accessor :transportation_method
23
+
24
+ attr_accessor :project_id
25
+
26
+ attr_accessor :create_order
27
+
28
+ class EnumAttributeValidator
29
+ attr_reader :datatype
30
+ attr_reader :allowable_values
31
+
32
+ def initialize(datatype, allowable_values)
33
+ @allowable_values = allowable_values.map do |value|
34
+ case datatype.to_s
35
+ when /Integer/i
36
+ value.to_i
37
+ when /Float/i
38
+ value.to_f
39
+ else
40
+ value
41
+ end
42
+ end
43
+ end
44
+
45
+ def valid?(value)
46
+ !value || allowable_values.include?(value)
47
+ end
48
+ end
21
49
 
22
50
  # Attribute mapping from ruby-style variable name to JSON key.
23
51
  def self.attribute_map
24
52
  {
25
- :'email' => :'email',
26
- :'name' => :'name'
53
+ :'distance_m' => :'distance_m',
54
+ :'package_mass_g' => :'package_mass_g',
55
+ :'transportation_method' => :'transportation_method',
56
+ :'project_id' => :'project_id',
57
+ :'create_order' => :'create_order'
27
58
  }
28
59
  end
29
60
 
@@ -35,16 +66,19 @@ module Patch
35
66
  # Attribute type mapping.
36
67
  def self.openapi_types
37
68
  {
38
- :'email' => :'String',
39
- :'name' => :'String'
69
+ :'distance_m' => :'Integer',
70
+ :'package_mass_g' => :'Integer',
71
+ :'transportation_method' => :'String',
72
+ :'project_id' => :'String',
73
+ :'create_order' => :'Boolean'
40
74
  }
41
75
  end
42
76
 
43
77
  # List of attributes with nullable: true
44
78
  def self.openapi_nullable
45
79
  Set.new([
46
- :'email',
47
- :'name'
80
+ :'project_id',
81
+ :'create_order'
48
82
  ])
49
83
  end
50
84
 
@@ -53,8 +87,8 @@ module Patch
53
87
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
54
88
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
55
89
  def self.method_missing(message, *args, &block)
56
- if Object.const_defined?('Patch::V1OrdersIssuedTosApi::OPERATIONS') && Patch::V1OrdersIssuedTosApi::OPERATIONS.include?(message)
57
- Patch::V1OrdersIssuedTosApi.new.send(message, *args)
90
+ if Object.const_defined?('Patch::CreateEcommerceEstimateRequestsApi::OPERATIONS') && Patch::CreateEcommerceEstimateRequestsApi::OPERATIONS.include?(message)
91
+ Patch::CreateEcommerceEstimateRequestsApi.new.send(message, *args)
58
92
  else
59
93
  super
60
94
  end
@@ -64,23 +98,37 @@ module Patch
64
98
  # @param [Hash] attributes Model attributes in the form of hash
65
99
  def initialize(attributes = {})
66
100
  if (!attributes.is_a?(Hash))
67
- fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::V1OrdersIssuedTo` initialize method"
101
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateEcommerceEstimateRequest` initialize method"
68
102
  end
69
103
 
70
104
  # check to see if the attribute exists and convert string to symbol for hash key
71
105
  attributes = attributes.each_with_object({}) { |(k, v), h|
72
106
  if (!self.class.attribute_map.key?(k.to_sym))
73
- 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
107
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateEcommerceEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
74
108
  end
75
109
  h[k.to_sym] = v
76
110
  }
77
111
 
78
- if attributes.key?(:'email')
79
- self.email = attributes[:'email']
112
+ if attributes.key?(:'distance_m')
113
+ self.distance_m = attributes[:'distance_m']
114
+ end
115
+
116
+ if attributes.key?(:'package_mass_g')
117
+ self.package_mass_g = attributes[:'package_mass_g']
80
118
  end
81
119
 
82
- if attributes.key?(:'name')
83
- self.name = attributes[:'name']
120
+ if attributes.key?(:'transportation_method')
121
+ self.transportation_method = attributes[:'transportation_method']
122
+ end
123
+
124
+ if attributes.key?(:'project_id')
125
+ self.project_id = attributes[:'project_id']
126
+ end
127
+
128
+ if attributes.key?(:'create_order')
129
+ self.create_order = attributes[:'create_order']
130
+ else
131
+ self.create_order = false
84
132
  end
85
133
  end
86
134
 
@@ -88,22 +136,108 @@ module Patch
88
136
  # @return Array for valid properties with the reasons
89
137
  def list_invalid_properties
90
138
  invalid_properties = Array.new
139
+ if @distance_m.nil?
140
+ invalid_properties.push('invalid value for "distance_m", distance_m cannot be nil.')
141
+ end
142
+
143
+ if @distance_m > 400000000
144
+ invalid_properties.push('invalid value for "distance_m", must be smaller than or equal to 400000000.')
145
+ end
146
+
147
+ if @distance_m < 0
148
+ invalid_properties.push('invalid value for "distance_m", must be greater than or equal to 0.')
149
+ end
150
+
151
+ if @package_mass_g.nil?
152
+ invalid_properties.push('invalid value for "package_mass_g", package_mass_g cannot be nil.')
153
+ end
154
+
155
+ if @package_mass_g > 2000000000
156
+ invalid_properties.push('invalid value for "package_mass_g", must be smaller than or equal to 2000000000.')
157
+ end
158
+
159
+ if @package_mass_g < 0
160
+ invalid_properties.push('invalid value for "package_mass_g", must be greater than or equal to 0.')
161
+ end
162
+
163
+ if @transportation_method.nil?
164
+ invalid_properties.push('invalid value for "transportation_method", transportation_method cannot be nil.')
165
+ end
166
+
91
167
  invalid_properties
92
168
  end
93
169
 
94
170
  # Check to see if the all the properties in the model are valid
95
171
  # @return true if the model is valid
96
172
  def valid?
173
+ return false if @distance_m.nil?
174
+ return false if @distance_m > 400000000
175
+ return false if @distance_m < 0
176
+ return false if @package_mass_g.nil?
177
+ return false if @package_mass_g > 2000000000
178
+ return false if @package_mass_g < 0
179
+ return false if @transportation_method.nil?
180
+ transportation_method_validator = EnumAttributeValidator.new('String', ["air", "rail", "road", "sea"])
181
+ return false unless transportation_method_validator.valid?(@transportation_method)
97
182
  true
98
183
  end
99
184
 
185
+ # Custom attribute writer method with validation
186
+ # @param [Object] distance_m Value to be assigned
187
+ def distance_m=(distance_m)
188
+ if distance_m.nil?
189
+ fail ArgumentError, 'distance_m cannot be nil'
190
+ end
191
+
192
+ if distance_m > 400000000
193
+ fail ArgumentError, 'invalid value for "distance_m", must be smaller than or equal to 400000000.'
194
+ end
195
+
196
+ if distance_m < 0
197
+ fail ArgumentError, 'invalid value for "distance_m", must be greater than or equal to 0.'
198
+ end
199
+
200
+ @distance_m = distance_m
201
+ end
202
+
203
+ # Custom attribute writer method with validation
204
+ # @param [Object] package_mass_g Value to be assigned
205
+ def package_mass_g=(package_mass_g)
206
+ if package_mass_g.nil?
207
+ fail ArgumentError, 'package_mass_g cannot be nil'
208
+ end
209
+
210
+ if package_mass_g > 2000000000
211
+ fail ArgumentError, 'invalid value for "package_mass_g", must be smaller than or equal to 2000000000.'
212
+ end
213
+
214
+ if package_mass_g < 0
215
+ fail ArgumentError, 'invalid value for "package_mass_g", must be greater than or equal to 0.'
216
+ end
217
+
218
+ @package_mass_g = package_mass_g
219
+ end
220
+
221
+ # Custom attribute writer method checking allowed values (enum).
222
+ # @param [Object] transportation_method Object to be assigned
223
+ def transportation_method=(transportation_method)
224
+ validator = EnumAttributeValidator.new('String', ["air", "rail", "road", "sea"])
225
+ unless validator.valid?(transportation_method)
226
+ fail ArgumentError, "invalid value for \"transportation_method\", must be one of #{validator.allowable_values}."
227
+ end
228
+ @transportation_method = transportation_method
229
+ end
230
+
100
231
  # Checks equality by comparing each attribute.
101
232
  # @param [Object] Object to be compared
102
233
  def ==(o)
103
234
  return true if self.equal?(o)
104
235
  self.class == o.class &&
105
- email == o.email &&
106
- name == o.name
236
+ distance_m == o.distance_m &&
237
+ package_mass_g == o.package_mass_g &&
238
+ transportation_method == o.transportation_method &&
239
+ project_id == o.project_id &&
240
+ create_order == o.create_order
107
241
  end
108
242
 
109
243
  # @see the `==` method
@@ -115,7 +249,7 @@ module Patch
115
249
  # Calculates hash code according to all attributes.
116
250
  # @return [Integer] Hash code
117
251
  def hash
118
- [email, name].hash
252
+ [distance_m, package_mass_g, transportation_method, project_id, create_order].hash
119
253
  end
120
254
 
121
255
  # Builds the object from hash
@@ -94,7 +94,7 @@ module Patch
94
94
  :'currency' => :'String',
95
95
  :'amount' => :'Integer',
96
96
  :'unit' => :'String',
97
- :'issued_to' => :'V1OrdersIssuedTo'
97
+ :'issued_to' => :'OrderIssuedTo'
98
98
  }
99
99
  end
100
100
 
@@ -111,7 +111,6 @@ module Patch
111
111
  :'currency',
112
112
  :'amount',
113
113
  :'unit',
114
- :'issued_to'
115
114
  ])
116
115
  end
117
116
 
@@ -232,7 +231,7 @@ module Patch
232
231
  return false if !@mass_g.nil? && @mass_g > 100000000000
233
232
  return false if !@mass_g.nil? && @mass_g < 0
234
233
  return false if !@total_price_cents_usd.nil? && @total_price_cents_usd < 1
235
- state_validator = EnumAttributeValidator.new('String', ["draft", "placed"])
234
+ state_validator = EnumAttributeValidator.new('String', ["draft", "reserved", "placed"])
236
235
  return false unless state_validator.valid?(@state)
237
236
  return false if !@vintage_year.nil? && @vintage_year > 2100
238
237
  return false if !@vintage_year.nil? && @vintage_year < 1900
@@ -271,7 +270,7 @@ module Patch
271
270
  # Custom attribute writer method checking allowed values (enum).
272
271
  # @param [Object] state Object to be assigned
273
272
  def state=(state)
274
- validator = EnumAttributeValidator.new('String', ["draft", "placed"])
273
+ validator = EnumAttributeValidator.new('String', ["draft", "reserved", "placed"])
275
274
  unless validator.valid?(state)
276
275
  fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}."
277
276
  end
@@ -0,0 +1,404 @@
1
+ =begin
2
+ #Patch API V1
3
+
4
+ #The core API used to integrate with Patch's service
5
+
6
+ The version of the OpenAPI document: v1
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 CreateRailShippingEstimateRequest
18
+ attr_accessor :destination_country_code
19
+
20
+ attr_accessor :destination_locode
21
+
22
+ attr_accessor :destination_postal_code
23
+
24
+ attr_accessor :origin_country_code
25
+
26
+ attr_accessor :origin_locode
27
+
28
+ attr_accessor :origin_postal_code
29
+
30
+ attr_accessor :fuel_type
31
+
32
+ attr_accessor :freight_mass_g
33
+
34
+ attr_accessor :emissions_scope
35
+
36
+ attr_accessor :project_id
37
+
38
+ attr_accessor :create_order
39
+
40
+ class EnumAttributeValidator
41
+ attr_reader :datatype
42
+ attr_reader :allowable_values
43
+
44
+ def initialize(datatype, allowable_values)
45
+ @allowable_values = allowable_values.map do |value|
46
+ case datatype.to_s
47
+ when /Integer/i
48
+ value.to_i
49
+ when /Float/i
50
+ value.to_f
51
+ else
52
+ value
53
+ end
54
+ end
55
+ end
56
+
57
+ def valid?(value)
58
+ !value || allowable_values.include?(value)
59
+ end
60
+ end
61
+
62
+ # Attribute mapping from ruby-style variable name to JSON key.
63
+ def self.attribute_map
64
+ {
65
+ :'destination_country_code' => :'destination_country_code',
66
+ :'destination_locode' => :'destination_locode',
67
+ :'destination_postal_code' => :'destination_postal_code',
68
+ :'origin_country_code' => :'origin_country_code',
69
+ :'origin_locode' => :'origin_locode',
70
+ :'origin_postal_code' => :'origin_postal_code',
71
+ :'fuel_type' => :'fuel_type',
72
+ :'freight_mass_g' => :'freight_mass_g',
73
+ :'emissions_scope' => :'emissions_scope',
74
+ :'project_id' => :'project_id',
75
+ :'create_order' => :'create_order'
76
+ }
77
+ end
78
+
79
+ # Returns all the JSON keys this model knows about
80
+ def self.acceptable_attributes
81
+ attribute_map.values
82
+ end
83
+
84
+ # Attribute type mapping.
85
+ def self.openapi_types
86
+ {
87
+ :'destination_country_code' => :'String',
88
+ :'destination_locode' => :'String',
89
+ :'destination_postal_code' => :'String',
90
+ :'origin_country_code' => :'String',
91
+ :'origin_locode' => :'String',
92
+ :'origin_postal_code' => :'String',
93
+ :'fuel_type' => :'String',
94
+ :'freight_mass_g' => :'Integer',
95
+ :'emissions_scope' => :'String',
96
+ :'project_id' => :'String',
97
+ :'create_order' => :'Boolean'
98
+ }
99
+ end
100
+
101
+ # List of attributes with nullable: true
102
+ def self.openapi_nullable
103
+ Set.new([
104
+ :'destination_country_code',
105
+ :'destination_locode',
106
+ :'destination_postal_code',
107
+ :'origin_country_code',
108
+ :'origin_locode',
109
+ :'origin_postal_code',
110
+ :'fuel_type',
111
+ :'emissions_scope',
112
+ :'project_id',
113
+ :'create_order'
114
+ ])
115
+ end
116
+
117
+
118
+ # Allows models with corresponding API classes to delegate API operations to those API classes
119
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
120
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
121
+ def self.method_missing(message, *args, &block)
122
+ if Object.const_defined?('Patch::CreateRailShippingEstimateRequestsApi::OPERATIONS') && Patch::CreateRailShippingEstimateRequestsApi::OPERATIONS.include?(message)
123
+ Patch::CreateRailShippingEstimateRequestsApi.new.send(message, *args)
124
+ else
125
+ super
126
+ end
127
+ end
128
+
129
+ # Initializes the object
130
+ # @param [Hash] attributes Model attributes in the form of hash
131
+ def initialize(attributes = {})
132
+ if (!attributes.is_a?(Hash))
133
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateRailShippingEstimateRequest` initialize method"
134
+ end
135
+
136
+ # check to see if the attribute exists and convert string to symbol for hash key
137
+ attributes = attributes.each_with_object({}) { |(k, v), h|
138
+ if (!self.class.attribute_map.key?(k.to_sym))
139
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateRailShippingEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
140
+ end
141
+ h[k.to_sym] = v
142
+ }
143
+
144
+ if attributes.key?(:'destination_country_code')
145
+ self.destination_country_code = attributes[:'destination_country_code']
146
+ end
147
+
148
+ if attributes.key?(:'destination_locode')
149
+ self.destination_locode = attributes[:'destination_locode']
150
+ end
151
+
152
+ if attributes.key?(:'destination_postal_code')
153
+ self.destination_postal_code = attributes[:'destination_postal_code']
154
+ end
155
+
156
+ if attributes.key?(:'origin_country_code')
157
+ self.origin_country_code = attributes[:'origin_country_code']
158
+ end
159
+
160
+ if attributes.key?(:'origin_locode')
161
+ self.origin_locode = attributes[:'origin_locode']
162
+ end
163
+
164
+ if attributes.key?(:'origin_postal_code')
165
+ self.origin_postal_code = attributes[:'origin_postal_code']
166
+ end
167
+
168
+ if attributes.key?(:'fuel_type')
169
+ self.fuel_type = attributes[:'fuel_type']
170
+ else
171
+ self.fuel_type = 'default'
172
+ end
173
+
174
+ if attributes.key?(:'freight_mass_g')
175
+ self.freight_mass_g = attributes[:'freight_mass_g']
176
+ end
177
+
178
+ if attributes.key?(:'emissions_scope')
179
+ self.emissions_scope = attributes[:'emissions_scope']
180
+ else
181
+ self.emissions_scope = 'ttw'
182
+ end
183
+
184
+ if attributes.key?(:'project_id')
185
+ self.project_id = attributes[:'project_id']
186
+ end
187
+
188
+ if attributes.key?(:'create_order')
189
+ self.create_order = attributes[:'create_order']
190
+ else
191
+ self.create_order = false
192
+ end
193
+ end
194
+
195
+ # Show invalid properties with the reasons. Usually used together with valid?
196
+ # @return Array for valid properties with the reasons
197
+ def list_invalid_properties
198
+ invalid_properties = Array.new
199
+ if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
200
+ invalid_properties.push('invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.')
201
+ end
202
+
203
+ if !@freight_mass_g.nil? && @freight_mass_g < 0
204
+ invalid_properties.push('invalid value for "freight_mass_g", must be greater than or equal to 0.')
205
+ end
206
+
207
+ invalid_properties
208
+ end
209
+
210
+ # Check to see if the all the properties in the model are valid
211
+ # @return true if the model is valid
212
+ def valid?
213
+ fuel_type_validator = EnumAttributeValidator.new('String', ["default", "diesel", "elec"])
214
+ return false unless fuel_type_validator.valid?(@fuel_type)
215
+ return false if !@freight_mass_g.nil? && @freight_mass_g > 2000000000
216
+ return false if !@freight_mass_g.nil? && @freight_mass_g < 0
217
+ emissions_scope_validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
218
+ return false unless emissions_scope_validator.valid?(@emissions_scope)
219
+ true
220
+ end
221
+
222
+ # Custom attribute writer method checking allowed values (enum).
223
+ # @param [Object] fuel_type Object to be assigned
224
+ def fuel_type=(fuel_type)
225
+ validator = EnumAttributeValidator.new('String', ["default", "diesel", "elec"])
226
+ unless validator.valid?(fuel_type)
227
+ fail ArgumentError, "invalid value for \"fuel_type\", must be one of #{validator.allowable_values}."
228
+ end
229
+ @fuel_type = fuel_type
230
+ end
231
+
232
+ # Custom attribute writer method with validation
233
+ # @param [Object] freight_mass_g Value to be assigned
234
+ def freight_mass_g=(freight_mass_g)
235
+ if !freight_mass_g.nil? && freight_mass_g > 2000000000
236
+ fail ArgumentError, 'invalid value for "freight_mass_g", must be smaller than or equal to 2000000000.'
237
+ end
238
+
239
+ if !freight_mass_g.nil? && freight_mass_g < 0
240
+ fail ArgumentError, 'invalid value for "freight_mass_g", must be greater than or equal to 0.'
241
+ end
242
+
243
+ @freight_mass_g = freight_mass_g
244
+ end
245
+
246
+ # Custom attribute writer method checking allowed values (enum).
247
+ # @param [Object] emissions_scope Object to be assigned
248
+ def emissions_scope=(emissions_scope)
249
+ validator = EnumAttributeValidator.new('String', ["wtt", "ttw", "wtw"])
250
+ unless validator.valid?(emissions_scope)
251
+ fail ArgumentError, "invalid value for \"emissions_scope\", must be one of #{validator.allowable_values}."
252
+ end
253
+ @emissions_scope = emissions_scope
254
+ end
255
+
256
+ # Checks equality by comparing each attribute.
257
+ # @param [Object] Object to be compared
258
+ def ==(o)
259
+ return true if self.equal?(o)
260
+ self.class == o.class &&
261
+ destination_country_code == o.destination_country_code &&
262
+ destination_locode == o.destination_locode &&
263
+ destination_postal_code == o.destination_postal_code &&
264
+ origin_country_code == o.origin_country_code &&
265
+ origin_locode == o.origin_locode &&
266
+ origin_postal_code == o.origin_postal_code &&
267
+ fuel_type == o.fuel_type &&
268
+ freight_mass_g == o.freight_mass_g &&
269
+ emissions_scope == o.emissions_scope &&
270
+ project_id == o.project_id &&
271
+ create_order == o.create_order
272
+ end
273
+
274
+ # @see the `==` method
275
+ # @param [Object] Object to be compared
276
+ def eql?(o)
277
+ self == o
278
+ end
279
+
280
+ # Calculates hash code according to all attributes.
281
+ # @return [Integer] Hash code
282
+ def hash
283
+ [destination_country_code, destination_locode, destination_postal_code, origin_country_code, origin_locode, origin_postal_code, fuel_type, freight_mass_g, emissions_scope, project_id, create_order].hash
284
+ end
285
+
286
+ # Builds the object from hash
287
+ # @param [Hash] attributes Model attributes in the form of hash
288
+ # @return [Object] Returns the model itself
289
+ def self.build_from_hash(attributes)
290
+ new.build_from_hash(attributes)
291
+ end
292
+
293
+ # Builds the object from hash
294
+ # @param [Hash] attributes Model attributes in the form of hash
295
+ # @return [Object] Returns the model itself
296
+ def build_from_hash(attributes)
297
+ return nil unless attributes.is_a?(Hash)
298
+ self.class.openapi_types.each_pair do |key, type|
299
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
300
+ self.send("#{key}=", nil)
301
+ elsif type =~ /\AArray<(.*)>/i
302
+ # check to ensure the input is an array given that the attribute
303
+ # is documented as an array but the input is not
304
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
305
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
306
+ end
307
+ elsif !attributes[self.class.attribute_map[key]].nil?
308
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
309
+ end
310
+ end
311
+
312
+ self
313
+ end
314
+
315
+ # Deserializes the data based on type
316
+ # @param string type Data type
317
+ # @param string value Value to be deserialized
318
+ # @return [Object] Deserialized data
319
+ def _deserialize(type, value)
320
+ case type.to_sym
321
+ when :Time
322
+ Time.parse(value)
323
+ when :Date
324
+ Date.parse(value)
325
+ when :String
326
+ value.to_s
327
+ when :Integer
328
+ value.to_i
329
+ when :Float
330
+ value.to_f
331
+ when :Boolean
332
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
333
+ true
334
+ else
335
+ false
336
+ end
337
+ when :Object
338
+ # generic object (usually a Hash), return directly
339
+ value
340
+ when /\AArray<(?<inner_type>.+)>\z/
341
+ inner_type = Regexp.last_match[:inner_type]
342
+ value.map { |v| _deserialize(inner_type, v) }
343
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
344
+ k_type = Regexp.last_match[:k_type]
345
+ v_type = Regexp.last_match[:v_type]
346
+ {}.tap do |hash|
347
+ value.each do |k, v|
348
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
349
+ end
350
+ end
351
+ else # model
352
+ # models (e.g. Pet) or oneOf
353
+ klass = Patch.const_get(type)
354
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
355
+ end
356
+ end
357
+
358
+ # Returns the string representation of the object
359
+ # @return [String] String presentation of the object
360
+ def to_s
361
+ to_hash.to_s
362
+ end
363
+
364
+ # to_body is an alias to to_hash (backward compatibility)
365
+ # @return [Hash] Returns the object in the form of hash
366
+ def to_body
367
+ to_hash
368
+ end
369
+
370
+ # Returns the object in the form of hash
371
+ # @return [Hash] Returns the object in the form of hash
372
+ def to_hash
373
+ hash = {}
374
+ self.class.attribute_map.each_pair do |attr, param|
375
+ value = self.send(attr)
376
+ if value.nil?
377
+ is_nullable = self.class.openapi_nullable.include?(attr)
378
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
379
+ end
380
+
381
+ hash[param] = _to_hash(value)
382
+ end
383
+ hash
384
+ end
385
+
386
+ # Outputs non-array value in the form of hash
387
+ # For object, use to_hash. Otherwise, just return the value
388
+ # @param [Object] value Any valid value
389
+ # @return [Hash] Returns the value in the form of hash
390
+ def _to_hash(value)
391
+ if value.is_a?(Array)
392
+ value.compact.map { |v| _to_hash(v) }
393
+ elsif value.is_a?(Hash)
394
+ {}.tap do |hash|
395
+ value.each { |k, v| hash[k] = _to_hash(v) }
396
+ end
397
+ elsif value.respond_to? :to_hash
398
+ value.to_hash
399
+ else
400
+ value
401
+ end
402
+ end
403
+ end
404
+ end