lob 6.0.7 → 6.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/docs/Address.md +43 -46
- data/docs/CountryExtendedExpandedNoUs.md +15 -0
- data/docs/IntlAddress.md +54 -0
- data/docs/UsAddress.md +54 -0
- data/lib/openapi_client/models/address.rb +76 -587
- data/lib/openapi_client/models/country_extended_expanded_no_us.rb +254 -0
- data/lib/openapi_client/models/intl_address.rb +624 -0
- data/lib/openapi_client/models/us_address.rb +644 -0
- data/lib/openapi_client/version.rb +1 -1
- metadata +8 -2
@@ -14,603 +14,92 @@ require 'date'
|
|
14
14
|
require 'time'
|
15
15
|
|
16
16
|
module Lob
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
# 2 letter state short-name code
|
46
|
-
attr_accessor :address_state
|
47
|
-
|
48
|
-
# Must follow the ZIP format of `12345` or ZIP+4 format of `12345-1234`.
|
49
|
-
attr_accessor :address_zip
|
50
|
-
|
51
|
-
attr_accessor :address_country
|
52
|
-
|
53
|
-
attr_accessor :object
|
54
|
-
|
55
|
-
# A timestamp in ISO 8601 format of the date the resource was created.
|
56
|
-
attr_accessor :date_created
|
57
|
-
|
58
|
-
# A timestamp in ISO 8601 format of the date the resource was last modified.
|
59
|
-
attr_accessor :date_modified
|
60
|
-
|
61
|
-
# Only returned if the resource has been successfully deleted.
|
62
|
-
attr_accessor :deleted
|
63
|
-
|
64
|
-
# Only returned for accounts on certain <a href=\"https://dashboard.lob.com/#/settings/editions\">Print & Mail Editions</a>. Value is `true` if the address was altered because the recipient filed for a <a href=\"#ncoa\">National Change of Address (NCOA)</a>, `false` if the NCOA check was run but no altered address was found, and `null` if the NCOA check was not run. The NCOA check does not happen for non-US addresses, for non-deliverable US addresses, or for addresses created before the NCOA feature was added to your account.
|
65
|
-
attr_accessor :recipient_moved
|
66
|
-
|
67
|
-
class EnumAttributeValidator
|
68
|
-
attr_reader :datatype
|
69
|
-
attr_reader :allowable_values
|
70
|
-
|
71
|
-
def initialize(datatype, allowable_values)
|
72
|
-
@allowable_values = allowable_values.map do |value|
|
73
|
-
case datatype.to_s
|
74
|
-
when /Integer/i
|
75
|
-
value.to_i
|
76
|
-
when /Float/i
|
77
|
-
value.to_f
|
78
|
-
else
|
79
|
-
value
|
17
|
+
module Address
|
18
|
+
class << self
|
19
|
+
# List of class defined in oneOf (OpenAPI v3)
|
20
|
+
def openapi_one_of
|
21
|
+
[
|
22
|
+
:'IntlAddress',
|
23
|
+
:'UsAddress'
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Builds the object
|
28
|
+
# @param [Mixed] Data to be matched against the list of oneOf items
|
29
|
+
# @return [Object] Returns the model or the data itself
|
30
|
+
def build(data)
|
31
|
+
# Go through the list of oneOf items and attempt to identify the appropriate one.
|
32
|
+
# Note:
|
33
|
+
# - We do not attempt to check whether exactly one item matches.
|
34
|
+
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
|
35
|
+
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
|
36
|
+
# - TODO: scalar values are de facto behaving as if they were nullable.
|
37
|
+
# - TODO: logging when debugging is set.
|
38
|
+
openapi_one_of.each do |klass|
|
39
|
+
begin
|
40
|
+
next if klass == :AnyType # "nullable: true"
|
41
|
+
typed_data = find_and_cast_into_type(klass, data)
|
42
|
+
return typed_data if typed_data
|
43
|
+
rescue # rescue all errors so we keep iterating even if the current item lookup raises
|
80
44
|
end
|
81
45
|
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def valid?(value)
|
85
|
-
!value || allowable_values.include?(value)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# Attribute mapping from ruby-style variable name to JSON key.
|
90
|
-
def self.attribute_map
|
91
|
-
{
|
92
|
-
:'id' => :'id',
|
93
|
-
:'description' => :'description',
|
94
|
-
:'name' => :'name',
|
95
|
-
:'company' => :'company',
|
96
|
-
:'phone' => :'phone',
|
97
|
-
:'email' => :'email',
|
98
|
-
:'metadata' => :'metadata',
|
99
|
-
:'address_line1' => :'address_line1',
|
100
|
-
:'address_line2' => :'address_line2',
|
101
|
-
:'address_city' => :'address_city',
|
102
|
-
:'address_state' => :'address_state',
|
103
|
-
:'address_zip' => :'address_zip',
|
104
|
-
:'address_country' => :'address_country',
|
105
|
-
:'object' => :'object',
|
106
|
-
:'date_created' => :'date_created',
|
107
|
-
:'date_modified' => :'date_modified',
|
108
|
-
:'deleted' => :'deleted',
|
109
|
-
:'recipient_moved' => :'recipient_moved'
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
# Returns all the JSON keys this model knows about
|
114
|
-
def self.acceptable_attributes
|
115
|
-
attribute_map.values
|
116
|
-
end
|
117
|
-
|
118
|
-
# Attribute type mapping.
|
119
|
-
def self.openapi_types
|
120
|
-
{
|
121
|
-
:'id' => :'String',
|
122
|
-
:'description' => :'String',
|
123
|
-
:'name' => :'String',
|
124
|
-
:'company' => :'String',
|
125
|
-
:'phone' => :'String',
|
126
|
-
:'email' => :'String',
|
127
|
-
:'metadata' => :'Hash<String, String>',
|
128
|
-
:'address_line1' => :'String',
|
129
|
-
:'address_line2' => :'String',
|
130
|
-
:'address_city' => :'String',
|
131
|
-
:'address_state' => :'String',
|
132
|
-
:'address_zip' => :'String',
|
133
|
-
:'address_country' => :'CountryExtendedExpanded',
|
134
|
-
:'object' => :'String',
|
135
|
-
:'date_created' => :'Time',
|
136
|
-
:'date_modified' => :'Time',
|
137
|
-
:'deleted' => :'Boolean',
|
138
|
-
:'recipient_moved' => :'Boolean'
|
139
|
-
}
|
140
|
-
end
|
141
|
-
|
142
|
-
# List of attributes with nullable: true
|
143
|
-
def self.openapi_nullable
|
144
|
-
Set.new([
|
145
|
-
:'description',
|
146
|
-
:'name',
|
147
|
-
:'company',
|
148
|
-
:'phone',
|
149
|
-
:'email',
|
150
|
-
:'address_line2',
|
151
|
-
:'recipient_moved'
|
152
|
-
])
|
153
|
-
end
|
154
|
-
|
155
|
-
# Initializes the object
|
156
|
-
# @param [Hash] attributes Model attributes in the form of hash
|
157
|
-
def initialize(attributes = {})
|
158
|
-
if (!attributes.is_a?(Hash))
|
159
|
-
fail ArgumentError, "The input argument (attributes) must be a hash in `Lob::Address` initialize method"
|
160
|
-
end
|
161
|
-
|
162
|
-
# check to see if the attribute exists and convert string to symbol for hash key
|
163
|
-
attributes = attributes.each_with_object({}) { |(k, v), h|
|
164
|
-
if (!self.class.attribute_map.key?(k.to_sym))
|
165
|
-
fail ArgumentError, "`#{k}` is not a valid attribute in `Lob::Address`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
166
|
-
end
|
167
|
-
h[k.to_sym] = v
|
168
|
-
}
|
169
|
-
|
170
|
-
if attributes.key?(:'id')
|
171
|
-
self.id = attributes[:'id']
|
172
|
-
end
|
173
|
-
|
174
|
-
if attributes.key?(:'description')
|
175
|
-
self.description = attributes[:'description']
|
176
|
-
end
|
177
|
-
|
178
|
-
if attributes.key?(:'name')
|
179
|
-
self.name = attributes[:'name']
|
180
|
-
end
|
181
|
-
|
182
|
-
if attributes.key?(:'company')
|
183
|
-
self.company = attributes[:'company']
|
184
|
-
end
|
185
|
-
|
186
|
-
if attributes.key?(:'phone')
|
187
|
-
self.phone = attributes[:'phone']
|
188
|
-
end
|
189
|
-
|
190
|
-
if attributes.key?(:'email')
|
191
|
-
self.email = attributes[:'email']
|
192
|
-
end
|
193
|
-
|
194
|
-
if attributes.key?(:'metadata')
|
195
|
-
if (value = attributes[:'metadata']).is_a?(Hash)
|
196
|
-
self.metadata = value
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
if attributes.key?(:'address_line1')
|
201
|
-
self.address_line1 = attributes[:'address_line1']
|
202
|
-
end
|
203
|
-
|
204
|
-
if attributes.key?(:'address_line2')
|
205
|
-
self.address_line2 = attributes[:'address_line2']
|
206
|
-
end
|
207
|
-
|
208
|
-
if attributes.key?(:'address_city')
|
209
|
-
self.address_city = attributes[:'address_city']
|
210
|
-
end
|
211
|
-
|
212
|
-
if attributes.key?(:'address_state')
|
213
|
-
self.address_state = attributes[:'address_state']
|
214
|
-
end
|
215
|
-
|
216
|
-
if attributes.key?(:'address_zip')
|
217
|
-
self.address_zip = attributes[:'address_zip']
|
218
|
-
end
|
219
|
-
|
220
|
-
if attributes.key?(:'address_country')
|
221
|
-
self.address_country = attributes[:'address_country']
|
222
|
-
end
|
223
|
-
|
224
|
-
if attributes.key?(:'object')
|
225
|
-
self.object = attributes[:'object']
|
226
|
-
else
|
227
|
-
self.object = 'address'
|
228
|
-
end
|
229
|
-
|
230
|
-
if attributes.key?(:'date_created')
|
231
|
-
self.date_created = attributes[:'date_created']
|
232
|
-
end
|
233
|
-
|
234
|
-
if attributes.key?(:'date_modified')
|
235
|
-
self.date_modified = attributes[:'date_modified']
|
236
|
-
end
|
237
|
-
|
238
|
-
if attributes.key?(:'deleted')
|
239
|
-
self.deleted = attributes[:'deleted']
|
240
|
-
end
|
241
|
-
|
242
|
-
if attributes.key?(:'recipient_moved')
|
243
|
-
self.recipient_moved = attributes[:'recipient_moved']
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
# Show invalid properties with the reasons. Usually used together with valid?
|
248
|
-
# @return Array for valid properties with the reasons
|
249
|
-
def list_invalid_properties
|
250
|
-
invalid_properties = Array.new
|
251
|
-
pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/)
|
252
|
-
if !@id.nil? && @id !~ pattern
|
253
|
-
invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.")
|
254
|
-
end
|
255
|
-
|
256
|
-
if !@description.nil? && @description.to_s.length > 255
|
257
|
-
invalid_properties.push('invalid value for "description", the character length must be smaller than or equal to 255.')
|
258
|
-
end
|
259
|
-
|
260
|
-
if !@name.nil? && @name.to_s.length > 40
|
261
|
-
invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 40.')
|
262
|
-
end
|
263
|
-
|
264
|
-
if !@company.nil? && @company.to_s.length > 40
|
265
|
-
invalid_properties.push('invalid value for "company", the character length must be smaller than or equal to 40.')
|
266
|
-
end
|
267
|
-
|
268
|
-
if !@phone.nil? && @phone.to_s.length > 40
|
269
|
-
invalid_properties.push('invalid value for "phone", the character length must be smaller than or equal to 40.')
|
270
|
-
end
|
271
|
-
|
272
|
-
if !@email.nil? && @email.to_s.length > 100
|
273
|
-
invalid_properties.push('invalid value for "email", the character length must be smaller than or equal to 100.')
|
274
|
-
end
|
275
|
-
|
276
|
-
if !@address_line1.nil? && @address_line1.to_s.length > 64
|
277
|
-
invalid_properties.push('invalid value for "address_line1", the character length must be smaller than or equal to 64.')
|
278
|
-
end
|
279
|
-
|
280
|
-
if !@address_line2.nil? && @address_line2.to_s.length > 64
|
281
|
-
invalid_properties.push('invalid value for "address_line2", the character length must be smaller than or equal to 64.')
|
282
|
-
end
|
283
46
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
return false if !@address_zip.nil? && @address_zip !~ Regexp.new(/^\d{5}(-\d{4})?$/)
|
315
|
-
object_validator = EnumAttributeValidator.new('String', ["address"])
|
316
|
-
return false unless object_validator.valid?(@object)
|
317
|
-
true
|
318
|
-
end
|
319
|
-
|
320
|
-
# Custom attribute writer method with validation
|
321
|
-
# @param [Object] id Value to be assigned
|
322
|
-
def id=(id)
|
323
|
-
pattern = Regexp.new(/^adr_[a-zA-Z0-9]+$/)
|
324
|
-
if !id.nil? && id !~ pattern
|
325
|
-
fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}."
|
326
|
-
end
|
327
|
-
|
328
|
-
@id = id
|
329
|
-
end
|
330
|
-
|
331
|
-
# Custom attribute writer method with validation
|
332
|
-
# @param [Object] description Value to be assigned
|
333
|
-
def description=(description)
|
334
|
-
if !description.nil? && description.to_s.length > 255
|
335
|
-
fail ArgumentError, 'invalid value for "description", the character length must be smaller than or equal to 255.'
|
336
|
-
end
|
337
|
-
|
338
|
-
@description = description
|
339
|
-
end
|
340
|
-
|
341
|
-
# Custom attribute writer method with validation
|
342
|
-
# @param [Object] name Value to be assigned
|
343
|
-
def name=(name)
|
344
|
-
if !name.nil? && name.to_s.length > 40
|
345
|
-
fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 40.'
|
346
|
-
end
|
347
|
-
|
348
|
-
@name = name
|
349
|
-
end
|
350
|
-
|
351
|
-
# Custom attribute writer method with validation
|
352
|
-
# @param [Object] company Value to be assigned
|
353
|
-
def company=(company)
|
354
|
-
if !company.nil? && company.to_s.length > 40
|
355
|
-
fail ArgumentError, 'invalid value for "company", the character length must be smaller than or equal to 40.'
|
356
|
-
end
|
357
|
-
|
358
|
-
@company = company
|
359
|
-
end
|
360
|
-
|
361
|
-
# Custom attribute writer method with validation
|
362
|
-
# @param [Object] phone Value to be assigned
|
363
|
-
def phone=(phone)
|
364
|
-
if !phone.nil? && phone.to_s.length > 40
|
365
|
-
fail ArgumentError, 'invalid value for "phone", the character length must be smaller than or equal to 40.'
|
366
|
-
end
|
367
|
-
|
368
|
-
@phone = phone
|
369
|
-
end
|
370
|
-
|
371
|
-
# Custom attribute writer method with validation
|
372
|
-
# @param [Object] email Value to be assigned
|
373
|
-
def email=(email)
|
374
|
-
if !email.nil? && email.to_s.length > 100
|
375
|
-
fail ArgumentError, 'invalid value for "email", the character length must be smaller than or equal to 100.'
|
376
|
-
end
|
377
|
-
|
378
|
-
@email = email
|
379
|
-
end
|
380
|
-
|
381
|
-
# Custom attribute writer method with validation
|
382
|
-
# @param [Object] metadata Value to be assigned
|
383
|
-
def metadata=(metadata)
|
384
|
-
@metadata = metadata
|
385
|
-
end
|
386
|
-
|
387
|
-
# Custom attribute writer method with validation
|
388
|
-
# @param [Object] address_line1 Value to be assigned
|
389
|
-
def address_line1=(address_line1)
|
390
|
-
if !address_line1.nil? && address_line1.to_s.length > 64
|
391
|
-
fail ArgumentError, 'invalid value for "address_line1", the character length must be smaller than or equal to 64.'
|
392
|
-
end
|
393
|
-
|
394
|
-
@address_line1 = address_line1
|
395
|
-
end
|
396
|
-
|
397
|
-
# Custom attribute writer method with validation
|
398
|
-
# @param [Object] address_line2 Value to be assigned
|
399
|
-
def address_line2=(address_line2)
|
400
|
-
if !address_line2.nil? && address_line2.to_s.length > 64
|
401
|
-
fail ArgumentError, 'invalid value for "address_line2", the character length must be smaller than or equal to 64.'
|
402
|
-
end
|
403
|
-
|
404
|
-
@address_line2 = address_line2
|
405
|
-
end
|
406
|
-
|
407
|
-
# Custom attribute writer method with validation
|
408
|
-
# @param [Object] address_city Value to be assigned
|
409
|
-
def address_city=(address_city)
|
410
|
-
if !address_city.nil? && address_city.to_s.length > 200
|
411
|
-
fail ArgumentError, 'invalid value for "address_city", the character length must be smaller than or equal to 200.'
|
412
|
-
end
|
413
|
-
|
414
|
-
@address_city = address_city
|
415
|
-
end
|
416
|
-
|
417
|
-
# Custom attribute writer method with validation
|
418
|
-
# @param [Object] address_state Value to be assigned
|
419
|
-
def address_state=(address_state)
|
420
|
-
pattern = Regexp.new(/^[a-zA-Z]{2}$/)
|
421
|
-
if !address_state.nil? && address_state !~ pattern
|
422
|
-
fail ArgumentError, "invalid value for \"address_state\", must conform to the pattern #{pattern}."
|
423
|
-
end
|
424
|
-
|
425
|
-
@address_state = address_state
|
426
|
-
end
|
427
|
-
|
428
|
-
# Custom attribute writer method with validation
|
429
|
-
# @param [Object] address_zip Value to be assigned
|
430
|
-
def address_zip=(address_zip)
|
431
|
-
pattern = Regexp.new(/^\d{5}(-\d{4})?$/)
|
432
|
-
if !address_zip.nil? && address_zip !~ pattern
|
433
|
-
fail ArgumentError, "invalid value for \"address_zip\", must conform to the pattern #{pattern}."
|
434
|
-
end
|
435
|
-
|
436
|
-
@address_zip = address_zip
|
437
|
-
end
|
438
|
-
|
439
|
-
# Custom attribute writer method checking allowed values (enum).
|
440
|
-
# @param [Object] object Object to be assigned
|
441
|
-
def object=(object)
|
442
|
-
validator = EnumAttributeValidator.new('String', ["address"])
|
443
|
-
unless validator.valid?(object)
|
444
|
-
fail ArgumentError, "invalid value for \"object\", must be one of #{validator.allowable_values}."
|
445
|
-
end
|
446
|
-
@object = object
|
447
|
-
end
|
448
|
-
|
449
|
-
# Checks equality by comparing each attribute.
|
450
|
-
# @param [Object] Object to be compared
|
451
|
-
def ==(o)
|
452
|
-
return true if self.equal?(o)
|
453
|
-
self.class == o.class &&
|
454
|
-
id == o.id &&
|
455
|
-
description == o.description &&
|
456
|
-
name == o.name &&
|
457
|
-
company == o.company &&
|
458
|
-
phone == o.phone &&
|
459
|
-
email == o.email &&
|
460
|
-
metadata == o.metadata &&
|
461
|
-
address_line1 == o.address_line1 &&
|
462
|
-
address_line2 == o.address_line2 &&
|
463
|
-
address_city == o.address_city &&
|
464
|
-
address_state == o.address_state &&
|
465
|
-
address_zip == o.address_zip &&
|
466
|
-
address_country == o.address_country &&
|
467
|
-
object == o.object &&
|
468
|
-
date_created == o.date_created &&
|
469
|
-
date_modified == o.date_modified &&
|
470
|
-
deleted == o.deleted &&
|
471
|
-
recipient_moved == o.recipient_moved
|
472
|
-
end
|
473
|
-
|
474
|
-
# @see the `==` method
|
475
|
-
# @param [Object] Object to be compared
|
476
|
-
def eql?(o)
|
477
|
-
self == o
|
478
|
-
end
|
479
|
-
|
480
|
-
# Calculates hash code according to all attributes.
|
481
|
-
# @return [Integer] Hash code
|
482
|
-
def hash
|
483
|
-
[id, description, name, company, phone, email, metadata, address_line1, address_line2, address_city, address_state, address_zip, address_country, object, date_created, date_modified, deleted, recipient_moved].hash
|
484
|
-
end
|
485
|
-
|
486
|
-
|
487
|
-
# Builds the object from hash
|
488
|
-
# @param [Hash] attributes Model attributes in the form of hash
|
489
|
-
# @return [Object] Returns the model itself
|
490
|
-
def self.build_from_hash(attributes)
|
491
|
-
new.build_from_hash(attributes)
|
492
|
-
end
|
493
|
-
|
494
|
-
# Builds the object from hash
|
495
|
-
# @param [Hash] attributes Model attributes in the form of hash
|
496
|
-
# @return [Object] Returns the model itself
|
497
|
-
def build_from_hash(attributes)
|
498
|
-
return nil unless attributes.is_a?(Hash)
|
499
|
-
attributes = attributes.transform_keys(&:to_sym)
|
500
|
-
self.class.openapi_types.each_pair do |key, type|
|
501
|
-
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
502
|
-
self.send("#{key}=", nil) # // guardrails-disable-line
|
503
|
-
elsif type =~ /\AArray<(.*)>/i
|
504
|
-
# check to ensure the input is an array given that the attribute
|
505
|
-
# is documented as an array but the input is not
|
506
|
-
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
507
|
-
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) # // guardrails-disable-line
|
47
|
+
openapi_one_of.include?(:AnyType) ? data : nil
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
SchemaMismatchError = Class.new(StandardError)
|
53
|
+
|
54
|
+
# Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
|
55
|
+
def find_and_cast_into_type(klass, data)
|
56
|
+
return if data.nil?
|
57
|
+
|
58
|
+
case klass.to_s
|
59
|
+
when 'Boolean'
|
60
|
+
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
|
61
|
+
when 'Float'
|
62
|
+
return data if data.instance_of?(Float)
|
63
|
+
when 'Integer'
|
64
|
+
return data if data.instance_of?(Integer)
|
65
|
+
when 'Time'
|
66
|
+
return Time.parse(data)
|
67
|
+
when 'Date'
|
68
|
+
return Date.parse(data)
|
69
|
+
when 'String'
|
70
|
+
return data if data.instance_of?(String)
|
71
|
+
when 'Object' # "type: object"
|
72
|
+
return data if data.instance_of?(Hash)
|
73
|
+
when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
|
74
|
+
if data.instance_of?(Array)
|
75
|
+
sub_type = Regexp.last_match[:sub_type]
|
76
|
+
return data.map { |item| find_and_cast_into_type(sub_type, item) }
|
508
77
|
end
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
self.send("#{key}=", res) # // guardrails-disable-line
|
514
|
-
break
|
515
|
-
end
|
78
|
+
when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
|
79
|
+
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
|
80
|
+
sub_type = Regexp.last_match[:sub_type]
|
81
|
+
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
|
516
82
|
end
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
def _deserialize(type, value)
|
530
|
-
case type.to_sym
|
531
|
-
when :Time
|
532
|
-
Time.parse(value)
|
533
|
-
when :Date
|
534
|
-
Date.parse(value)
|
535
|
-
when :String
|
536
|
-
value.to_s
|
537
|
-
when :Integer
|
538
|
-
value.to_i
|
539
|
-
when :Float
|
540
|
-
value.to_f
|
541
|
-
when :Boolean
|
542
|
-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
543
|
-
true
|
544
|
-
else
|
545
|
-
false
|
546
|
-
end
|
547
|
-
when :Object
|
548
|
-
# generic object (usually a Hash), return directly
|
549
|
-
value
|
550
|
-
when /\AArray<(?<inner_type>.+)>\z/
|
551
|
-
inner_type = Regexp.last_match[:inner_type]
|
552
|
-
value.map { |v| _deserialize(inner_type, v) }
|
553
|
-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
554
|
-
k_type = Regexp.last_match[:k_type]
|
555
|
-
v_type = Regexp.last_match[:v_type]
|
556
|
-
{}.tap do |hash|
|
557
|
-
value.each do |k, v|
|
558
|
-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
83
|
+
else # model
|
84
|
+
const = Lob.const_get(klass)
|
85
|
+
if const
|
86
|
+
if const.respond_to?(:openapi_one_of) # nested oneOf model
|
87
|
+
model = const.build(data)
|
88
|
+
return model if model
|
89
|
+
else
|
90
|
+
# raise if data contains keys that are not known to the model
|
91
|
+
raise unless (data.keys - const.acceptable_attributes).empty?
|
92
|
+
model = const.build_from_hash(data)
|
93
|
+
return model if model && model.valid?
|
94
|
+
end
|
559
95
|
end
|
560
96
|
end
|
561
|
-
else # model
|
562
|
-
# models (e.g. Pet) or oneOf
|
563
|
-
klass = Lob.const_get(type)
|
564
|
-
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
# Returns the string representation of the object
|
569
|
-
# @return [String] String presentation of the object
|
570
|
-
def to_s
|
571
|
-
to_hash.to_s
|
572
|
-
end
|
573
|
-
|
574
|
-
# to_body is an alias to to_hash (backward compatibility)
|
575
|
-
# @return [Hash] Returns the object in the form of hash
|
576
|
-
def to_body
|
577
|
-
to_hash
|
578
|
-
end
|
579
|
-
|
580
|
-
# Returns the object in the form of hash
|
581
|
-
# @return [Hash] Returns the object in the form of hash
|
582
|
-
def to_hash
|
583
|
-
hash = {}
|
584
|
-
self.class.attribute_map.each_pair do |attr, param|
|
585
|
-
value = self.send(attr) # // guardrails-disable-line
|
586
|
-
if value.nil?
|
587
|
-
is_nullable = self.class.openapi_nullable.include?(attr)
|
588
|
-
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
589
|
-
end
|
590
97
|
|
591
|
-
|
98
|
+
raise # if no match by now, raise
|
99
|
+
rescue
|
100
|
+
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
|
592
101
|
end
|
593
|
-
hash
|
594
102
|
end
|
595
|
-
|
596
|
-
# Outputs non-array value in the form of hash
|
597
|
-
# For object, use to_hash. Otherwise, just return the value
|
598
|
-
# @param [Object] value Any valid value
|
599
|
-
# @return [Hash] Returns the value in the form of hash
|
600
|
-
def _to_hash(value)
|
601
|
-
if value.is_a?(Array)
|
602
|
-
value.compact.map { |v| _to_hash(v) }
|
603
|
-
elsif value.is_a?(Hash)
|
604
|
-
{}.tap do |hash|
|
605
|
-
value.each { |k, v| hash[k] = _to_hash(v) }
|
606
|
-
end
|
607
|
-
elsif value.respond_to? :to_hash
|
608
|
-
value.to_hash
|
609
|
-
else
|
610
|
-
value
|
611
|
-
end
|
612
|
-
end
|
613
|
-
|
614
103
|
end
|
615
104
|
|
616
105
|
end
|