moneykit 0.2.1 → 0.2.2

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +1 -1
  4. data/docs/ApiPublicTransactionsGetTransactionsResponse.md +24 -0
  5. data/docs/ApiPublicTransactionsLegacyGetTransactionsResponse.md +28 -0
  6. data/docs/BudCategory.md +20 -0
  7. data/docs/BudPrimaryCategory.md +15 -0
  8. data/docs/BudSubcategory.md +15 -0
  9. data/docs/CustomSandboxAccount.md +24 -0
  10. data/docs/CustomSandboxData.md +20 -0
  11. data/docs/GetLinksLink.md +20 -0
  12. data/docs/GetLinksResponse.md +20 -0
  13. data/docs/ImportTransactionsRequest.md +18 -0
  14. data/docs/ProductStateChangedWebhook.md +38 -0
  15. data/docs/Response401CorrectEnrichmentLinksIdTransactionsTxnIdEnrichmentPost.md +22 -0
  16. data/docs/Response401CreateLinkSessionLinkSessionPost.md +22 -0
  17. data/docs/Response401GetLinksLinksGet.md +22 -0
  18. data/docs/Response401ImportTransactionsLinksIdImportTransactionsPost.md +22 -0
  19. data/docs/Response401ResetLinkLinksIdResetPost.md +22 -0
  20. data/lib/moneykit/models/api_public_transactions_get_transactions_response.rb +321 -0
  21. data/lib/moneykit/models/api_public_transactions_legacy_get_transactions_response.rb +375 -0
  22. data/lib/moneykit/models/bud_category.rb +266 -0
  23. data/lib/moneykit/models/bud_primary_category.rb +61 -0
  24. data/lib/moneykit/models/bud_subcategory.rb +165 -0
  25. data/lib/moneykit/models/custom_sandbox_account.rb +300 -0
  26. data/lib/moneykit/models/custom_sandbox_data.rb +250 -0
  27. data/lib/moneykit/models/get_links_link.rb +261 -0
  28. data/lib/moneykit/models/get_links_response.rb +231 -0
  29. data/lib/moneykit/models/import_transactions_request.rb +238 -0
  30. data/lib/moneykit/models/product_state_changed_webhook.rb +493 -0
  31. data/lib/moneykit/models/response401_correct_enrichment_links_id_transactions_txn_id_enrichment_post.rb +104 -0
  32. data/lib/moneykit/models/response401_create_link_session_link_session_post.rb +103 -0
  33. data/lib/moneykit/models/response401_get_links_links_get.rb +103 -0
  34. data/lib/moneykit/models/response401_import_transactions_links_id_import_transactions_post.rb +103 -0
  35. data/lib/moneykit/models/response401_reset_link_links_id_reset_post.rb +104 -0
  36. data/lib/moneykit/version.rb +1 -1
  37. data/spec/models/api_public_transactions_get_transactions_response_spec.rb +54 -0
  38. data/spec/models/api_public_transactions_legacy_get_transactions_response_spec.rb +66 -0
  39. data/spec/models/bud_category_spec.rb +42 -0
  40. data/spec/models/bud_primary_category_spec.rb +30 -0
  41. data/spec/models/bud_subcategory_spec.rb +30 -0
  42. data/spec/models/custom_sandbox_account_spec.rb +54 -0
  43. data/spec/models/custom_sandbox_data_spec.rb +42 -0
  44. data/spec/models/get_links_link_spec.rb +42 -0
  45. data/spec/models/get_links_response_spec.rb +42 -0
  46. data/spec/models/import_transactions_request_spec.rb +36 -0
  47. data/spec/models/product_state_changed_webhook_spec.rb +108 -0
  48. data/spec/models/response401_correct_enrichment_links_id_transactions_txn_id_enrichment_post_spec.rb +21 -0
  49. data/spec/models/response401_create_link_session_link_session_post_spec.rb +21 -0
  50. data/spec/models/response401_get_links_links_get_spec.rb +21 -0
  51. data/spec/models/response401_import_transactions_links_id_import_transactions_post_spec.rb +21 -0
  52. data/spec/models/response401_reset_link_links_id_reset_post_spec.rb +21 -0
  53. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/byebug-12.0.0/gem_make.out +5 -5
  54. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/json-2.11.3/gem_make.out +5 -5
  55. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/prism-1.4.0/gem_make.out +5 -5
  56. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/racc-1.8.1/gem_make.out +5 -5
  57. metadata +66 -2
@@ -0,0 +1,493 @@
1
+ =begin
2
+ #MoneyKit API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 2023-02-18
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module MoneyKit
17
+ class ProductStateChangedWebhook
18
+ attr_accessor :webhook_major_version
19
+
20
+ attr_accessor :webhook_minor_version
21
+
22
+ attr_accessor :webhook_idempotency_key
23
+
24
+ attr_accessor :webhook_timestamp
25
+
26
+ attr_accessor :link_id
27
+
28
+ attr_accessor :link_tags
29
+
30
+ attr_accessor :webhook_event
31
+
32
+ attr_accessor :product
33
+
34
+ attr_accessor :state
35
+
36
+ attr_accessor :state_changed_at
37
+
38
+ attr_accessor :error_message
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
+ :'webhook_major_version' => :'webhook_major_version',
66
+ :'webhook_minor_version' => :'webhook_minor_version',
67
+ :'webhook_idempotency_key' => :'webhook_idempotency_key',
68
+ :'webhook_timestamp' => :'webhook_timestamp',
69
+ :'link_id' => :'link_id',
70
+ :'link_tags' => :'link_tags',
71
+ :'webhook_event' => :'webhook_event',
72
+ :'product' => :'product',
73
+ :'state' => :'state',
74
+ :'state_changed_at' => :'state_changed_at',
75
+ :'error_message' => :'error_message'
76
+ }
77
+ end
78
+
79
+ # Returns attribute mapping this model knows about
80
+ def self.acceptable_attribute_map
81
+ attribute_map
82
+ end
83
+
84
+ # Returns all the JSON keys this model knows about
85
+ def self.acceptable_attributes
86
+ acceptable_attribute_map.values
87
+ end
88
+
89
+ # Attribute type mapping.
90
+ def self.openapi_types
91
+ {
92
+ :'webhook_major_version' => :'Integer',
93
+ :'webhook_minor_version' => :'Integer',
94
+ :'webhook_idempotency_key' => :'String',
95
+ :'webhook_timestamp' => :'Time',
96
+ :'link_id' => :'String',
97
+ :'link_tags' => :'Array<String>',
98
+ :'webhook_event' => :'String',
99
+ :'product' => :'Product',
100
+ :'state' => :'LinkProductState',
101
+ :'state_changed_at' => :'Time',
102
+ :'error_message' => :'String'
103
+ }
104
+ end
105
+
106
+ # List of attributes with nullable: true
107
+ def self.openapi_nullable
108
+ Set.new([
109
+ ])
110
+ end
111
+
112
+ # Initializes the object
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ def initialize(attributes = {})
115
+ if (!attributes.is_a?(Hash))
116
+ fail ArgumentError, "The input argument (attributes) must be a hash in `MoneyKit::ProductStateChangedWebhook` initialize method"
117
+ end
118
+
119
+ # check to see if the attribute exists and convert string to symbol for hash key
120
+ acceptable_attribute_map = self.class.acceptable_attribute_map
121
+ attributes = attributes.each_with_object({}) { |(k, v), h|
122
+ if (!acceptable_attribute_map.key?(k.to_sym))
123
+ fail ArgumentError, "`#{k}` is not a valid attribute in `MoneyKit::ProductStateChangedWebhook`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
124
+ end
125
+ h[k.to_sym] = v
126
+ }
127
+
128
+ if attributes.key?(:'webhook_major_version')
129
+ self.webhook_major_version = attributes[:'webhook_major_version']
130
+ else
131
+ self.webhook_major_version = WEBHOOK_MAJOR_VERSION::N1
132
+ end
133
+
134
+ if attributes.key?(:'webhook_minor_version')
135
+ self.webhook_minor_version = attributes[:'webhook_minor_version']
136
+ else
137
+ self.webhook_minor_version = WEBHOOK_MINOR_VERSION::N0
138
+ end
139
+
140
+ if attributes.key?(:'webhook_idempotency_key')
141
+ self.webhook_idempotency_key = attributes[:'webhook_idempotency_key']
142
+ else
143
+ self.webhook_idempotency_key = nil
144
+ end
145
+
146
+ if attributes.key?(:'webhook_timestamp')
147
+ self.webhook_timestamp = attributes[:'webhook_timestamp']
148
+ else
149
+ self.webhook_timestamp = nil
150
+ end
151
+
152
+ if attributes.key?(:'link_id')
153
+ self.link_id = attributes[:'link_id']
154
+ else
155
+ self.link_id = nil
156
+ end
157
+
158
+ if attributes.key?(:'link_tags')
159
+ if (value = attributes[:'link_tags']).is_a?(Array)
160
+ self.link_tags = value
161
+ end
162
+ else
163
+ self.link_tags = nil
164
+ end
165
+
166
+ if attributes.key?(:'webhook_event')
167
+ self.webhook_event = attributes[:'webhook_event']
168
+ else
169
+ self.webhook_event = 'link.product_refresh'
170
+ end
171
+
172
+ if attributes.key?(:'product')
173
+ self.product = attributes[:'product']
174
+ else
175
+ self.product = nil
176
+ end
177
+
178
+ if attributes.key?(:'state')
179
+ self.state = attributes[:'state']
180
+ else
181
+ self.state = nil
182
+ end
183
+
184
+ if attributes.key?(:'state_changed_at')
185
+ self.state_changed_at = attributes[:'state_changed_at']
186
+ else
187
+ self.state_changed_at = nil
188
+ end
189
+
190
+ if attributes.key?(:'error_message')
191
+ self.error_message = attributes[:'error_message']
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
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
199
+ invalid_properties = Array.new
200
+ if @webhook_idempotency_key.nil?
201
+ invalid_properties.push('invalid value for "webhook_idempotency_key", webhook_idempotency_key cannot be nil.')
202
+ end
203
+
204
+ if @webhook_timestamp.nil?
205
+ invalid_properties.push('invalid value for "webhook_timestamp", webhook_timestamp cannot be nil.')
206
+ end
207
+
208
+ if @link_id.nil?
209
+ invalid_properties.push('invalid value for "link_id", link_id cannot be nil.')
210
+ end
211
+
212
+ if @link_tags.nil?
213
+ invalid_properties.push('invalid value for "link_tags", link_tags cannot be nil.')
214
+ end
215
+
216
+ if @product.nil?
217
+ invalid_properties.push('invalid value for "product", product cannot be nil.')
218
+ end
219
+
220
+ if @state.nil?
221
+ invalid_properties.push('invalid value for "state", state cannot be nil.')
222
+ end
223
+
224
+ if @state_changed_at.nil?
225
+ invalid_properties.push('invalid value for "state_changed_at", state_changed_at cannot be nil.')
226
+ end
227
+
228
+ invalid_properties
229
+ end
230
+
231
+ # Check to see if the all the properties in the model are valid
232
+ # @return true if the model is valid
233
+ def valid?
234
+ warn '[DEPRECATED] the `valid?` method is obsolete'
235
+ webhook_major_version_validator = EnumAttributeValidator.new('Integer', [1])
236
+ return false unless webhook_major_version_validator.valid?(@webhook_major_version)
237
+ webhook_minor_version_validator = EnumAttributeValidator.new('Integer', [0])
238
+ return false unless webhook_minor_version_validator.valid?(@webhook_minor_version)
239
+ return false if @webhook_idempotency_key.nil?
240
+ return false if @webhook_timestamp.nil?
241
+ return false if @link_id.nil?
242
+ return false if @link_tags.nil?
243
+ webhook_event_validator = EnumAttributeValidator.new('String', ["link.product_refresh"])
244
+ return false unless webhook_event_validator.valid?(@webhook_event)
245
+ return false if @product.nil?
246
+ return false if @state.nil?
247
+ return false if @state_changed_at.nil?
248
+ true
249
+ end
250
+
251
+ # Custom attribute writer method checking allowed values (enum).
252
+ # @param [Object] webhook_major_version Object to be assigned
253
+ def webhook_major_version=(webhook_major_version)
254
+ validator = EnumAttributeValidator.new('Integer', [1])
255
+ unless validator.valid?(webhook_major_version)
256
+ fail ArgumentError, "invalid value for \"webhook_major_version\", must be one of #{validator.allowable_values}."
257
+ end
258
+ @webhook_major_version = webhook_major_version
259
+ end
260
+
261
+ # Custom attribute writer method checking allowed values (enum).
262
+ # @param [Object] webhook_minor_version Object to be assigned
263
+ def webhook_minor_version=(webhook_minor_version)
264
+ validator = EnumAttributeValidator.new('Integer', [0])
265
+ unless validator.valid?(webhook_minor_version)
266
+ fail ArgumentError, "invalid value for \"webhook_minor_version\", must be one of #{validator.allowable_values}."
267
+ end
268
+ @webhook_minor_version = webhook_minor_version
269
+ end
270
+
271
+ # Custom attribute writer method with validation
272
+ # @param [Object] webhook_idempotency_key Value to be assigned
273
+ def webhook_idempotency_key=(webhook_idempotency_key)
274
+ if webhook_idempotency_key.nil?
275
+ fail ArgumentError, 'webhook_idempotency_key cannot be nil'
276
+ end
277
+
278
+ @webhook_idempotency_key = webhook_idempotency_key
279
+ end
280
+
281
+ # Custom attribute writer method with validation
282
+ # @param [Object] webhook_timestamp Value to be assigned
283
+ def webhook_timestamp=(webhook_timestamp)
284
+ if webhook_timestamp.nil?
285
+ fail ArgumentError, 'webhook_timestamp cannot be nil'
286
+ end
287
+
288
+ @webhook_timestamp = webhook_timestamp
289
+ end
290
+
291
+ # Custom attribute writer method with validation
292
+ # @param [Object] link_id Value to be assigned
293
+ def link_id=(link_id)
294
+ if link_id.nil?
295
+ fail ArgumentError, 'link_id cannot be nil'
296
+ end
297
+
298
+ @link_id = link_id
299
+ end
300
+
301
+ # Custom attribute writer method with validation
302
+ # @param [Object] link_tags Value to be assigned
303
+ def link_tags=(link_tags)
304
+ if link_tags.nil?
305
+ fail ArgumentError, 'link_tags cannot be nil'
306
+ end
307
+
308
+ @link_tags = link_tags
309
+ end
310
+
311
+ # Custom attribute writer method checking allowed values (enum).
312
+ # @param [Object] webhook_event Object to be assigned
313
+ def webhook_event=(webhook_event)
314
+ validator = EnumAttributeValidator.new('String', ["link.product_refresh"])
315
+ unless validator.valid?(webhook_event)
316
+ fail ArgumentError, "invalid value for \"webhook_event\", must be one of #{validator.allowable_values}."
317
+ end
318
+ @webhook_event = webhook_event
319
+ end
320
+
321
+ # Custom attribute writer method with validation
322
+ # @param [Object] product Value to be assigned
323
+ def product=(product)
324
+ if product.nil?
325
+ fail ArgumentError, 'product cannot be nil'
326
+ end
327
+
328
+ @product = product
329
+ end
330
+
331
+ # Custom attribute writer method with validation
332
+ # @param [Object] state Value to be assigned
333
+ def state=(state)
334
+ if state.nil?
335
+ fail ArgumentError, 'state cannot be nil'
336
+ end
337
+
338
+ @state = state
339
+ end
340
+
341
+ # Custom attribute writer method with validation
342
+ # @param [Object] state_changed_at Value to be assigned
343
+ def state_changed_at=(state_changed_at)
344
+ if state_changed_at.nil?
345
+ fail ArgumentError, 'state_changed_at cannot be nil'
346
+ end
347
+
348
+ @state_changed_at = state_changed_at
349
+ end
350
+
351
+ # Checks equality by comparing each attribute.
352
+ # @param [Object] Object to be compared
353
+ def ==(o)
354
+ return true if self.equal?(o)
355
+ self.class == o.class &&
356
+ webhook_major_version == o.webhook_major_version &&
357
+ webhook_minor_version == o.webhook_minor_version &&
358
+ webhook_idempotency_key == o.webhook_idempotency_key &&
359
+ webhook_timestamp == o.webhook_timestamp &&
360
+ link_id == o.link_id &&
361
+ link_tags == o.link_tags &&
362
+ webhook_event == o.webhook_event &&
363
+ product == o.product &&
364
+ state == o.state &&
365
+ state_changed_at == o.state_changed_at &&
366
+ error_message == o.error_message
367
+ end
368
+
369
+ # @see the `==` method
370
+ # @param [Object] Object to be compared
371
+ def eql?(o)
372
+ self == o
373
+ end
374
+
375
+ # Calculates hash code according to all attributes.
376
+ # @return [Integer] Hash code
377
+ def hash
378
+ [webhook_major_version, webhook_minor_version, webhook_idempotency_key, webhook_timestamp, link_id, link_tags, webhook_event, product, state, state_changed_at, error_message].hash
379
+ end
380
+
381
+ # Builds the object from hash
382
+ # @param [Hash] attributes Model attributes in the form of hash
383
+ # @return [Object] Returns the model itself
384
+ def self.build_from_hash(attributes)
385
+ return nil unless attributes.is_a?(Hash)
386
+ attributes = attributes.transform_keys(&:to_sym)
387
+ transformed_hash = {}
388
+ openapi_types.each_pair do |key, type|
389
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
390
+ transformed_hash["#{key}"] = nil
391
+ elsif type =~ /\AArray<(.*)>/i
392
+ # check to ensure the input is an array given that the attribute
393
+ # is documented as an array but the input is not
394
+ if attributes[attribute_map[key]].is_a?(Array)
395
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
396
+ end
397
+ elsif !attributes[attribute_map[key]].nil?
398
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
399
+ end
400
+ end
401
+ new(transformed_hash)
402
+ end
403
+
404
+ # Deserializes the data based on type
405
+ # @param string type Data type
406
+ # @param string value Value to be deserialized
407
+ # @return [Object] Deserialized data
408
+ def self._deserialize(type, value)
409
+ case type.to_sym
410
+ when :Time
411
+ Time.parse(value)
412
+ when :Date
413
+ ::Date.parse(value)
414
+ when :String
415
+ value.to_s
416
+ when :Integer
417
+ value.to_i
418
+ when :Float
419
+ value.to_f
420
+ when :Boolean
421
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
422
+ true
423
+ else
424
+ false
425
+ end
426
+ when :Object
427
+ # generic object (usually a Hash), return directly
428
+ value
429
+ when /\AArray<(?<inner_type>.+)>\z/
430
+ inner_type = Regexp.last_match[:inner_type]
431
+ value.map { |v| _deserialize(inner_type, v) }
432
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
433
+ k_type = Regexp.last_match[:k_type]
434
+ v_type = Regexp.last_match[:v_type]
435
+ {}.tap do |hash|
436
+ value.each do |k, v|
437
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
438
+ end
439
+ end
440
+ else # model
441
+ # models (e.g. Pet) or oneOf
442
+ klass = MoneyKit.const_get(type)
443
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
444
+ end
445
+ end
446
+
447
+ # Returns the string representation of the object
448
+ # @return [String] String presentation of the object
449
+ def to_s
450
+ to_hash.to_s
451
+ end
452
+
453
+ # to_body is an alias to to_hash (backward compatibility)
454
+ # @return [Hash] Returns the object in the form of hash
455
+ def to_body
456
+ to_hash
457
+ end
458
+
459
+ # Returns the object in the form of hash
460
+ # @return [Hash] Returns the object in the form of hash
461
+ def to_hash
462
+ hash = {}
463
+ self.class.attribute_map.each_pair do |attr, param|
464
+ value = self.send(attr)
465
+ if value.nil?
466
+ is_nullable = self.class.openapi_nullable.include?(attr)
467
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
468
+ end
469
+
470
+ hash[param] = _to_hash(value)
471
+ end
472
+ hash
473
+ end
474
+
475
+ # Outputs non-array value in the form of hash
476
+ # For object, use to_hash. Otherwise, just return the value
477
+ # @param [Object] value Any valid value
478
+ # @return [Hash] Returns the value in the form of hash
479
+ def _to_hash(value)
480
+ if value.is_a?(Array)
481
+ value.compact.map { |v| _to_hash(v) }
482
+ elsif value.is_a?(Hash)
483
+ {}.tap do |hash|
484
+ value.each { |k, v| hash[k] = _to_hash(v) }
485
+ end
486
+ elsif value.respond_to? :to_hash
487
+ value.to_hash
488
+ else
489
+ value
490
+ end
491
+ end
492
+ end
493
+ end
@@ -0,0 +1,104 @@
1
+ =begin
2
+ #MoneyKit API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 2023-02-18
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module MoneyKit
17
+ module Response401CorrectEnrichmentLinksIdTransactionsTxnIdEnrichmentPost
18
+ class << self
19
+ # List of class defined in anyOf (OpenAPI v3)
20
+ def openapi_any_of
21
+ [
22
+ :'APIErrorAuthExpiredAccessTokenResponse',
23
+ :'APIErrorAuthUnauthorizedResponse',
24
+ :'LinkErrorUnauthorizedAccessResponse'
25
+ ]
26
+ end
27
+
28
+ # Builds the object
29
+ # @param [Mixed] Data to be matched against the list of anyOf items
30
+ # @return [Object] Returns the model or the data itself
31
+ def build(data)
32
+ # Go through the list of anyOf items and attempt to identify the appropriate one.
33
+ # Note:
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_any_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
44
+ end
45
+ end
46
+
47
+ openapi_any_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) }
77
+ 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) }
82
+ end
83
+ else # model
84
+ const = MoneyKit.const_get(klass)
85
+ if const
86
+ if const.respond_to?(:openapi_any_of) # nested anyOf 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 if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
92
+ model = const.build_from_hash(data)
93
+ return model if model
94
+ end
95
+ end
96
+ end
97
+
98
+ raise # if no match by now, raise
99
+ rescue
100
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,103 @@
1
+ =begin
2
+ #MoneyKit API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 2023-02-18
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module MoneyKit
17
+ module Response401CreateLinkSessionLinkSessionPost
18
+ class << self
19
+ # List of class defined in anyOf (OpenAPI v3)
20
+ def openapi_any_of
21
+ [
22
+ :'APIErrorAuthExpiredAccessTokenResponse',
23
+ :'APIErrorAuthUnauthorizedResponse'
24
+ ]
25
+ end
26
+
27
+ # Builds the object
28
+ # @param [Mixed] Data to be matched against the list of anyOf items
29
+ # @return [Object] Returns the model or the data itself
30
+ def build(data)
31
+ # Go through the list of anyOf items and attempt to identify the appropriate one.
32
+ # Note:
33
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
34
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
35
+ # - TODO: scalar values are de facto behaving as if they were nullable.
36
+ # - TODO: logging when debugging is set.
37
+ openapi_any_of.each do |klass|
38
+ begin
39
+ next if klass == :AnyType # "nullable: true"
40
+ typed_data = find_and_cast_into_type(klass, data)
41
+ return typed_data if typed_data
42
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
43
+ end
44
+ end
45
+
46
+ openapi_any_of.include?(:AnyType) ? data : nil
47
+ end
48
+
49
+ private
50
+
51
+ SchemaMismatchError = Class.new(StandardError)
52
+
53
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
54
+ def find_and_cast_into_type(klass, data)
55
+ return if data.nil?
56
+
57
+ case klass.to_s
58
+ when 'Boolean'
59
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
60
+ when 'Float'
61
+ return data if data.instance_of?(Float)
62
+ when 'Integer'
63
+ return data if data.instance_of?(Integer)
64
+ when 'Time'
65
+ return Time.parse(data)
66
+ when 'Date'
67
+ return ::Date.parse(data)
68
+ when 'String'
69
+ return data if data.instance_of?(String)
70
+ when 'Object' # "type: object"
71
+ return data if data.instance_of?(Hash)
72
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
73
+ if data.instance_of?(Array)
74
+ sub_type = Regexp.last_match[:sub_type]
75
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
76
+ end
77
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
78
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
79
+ sub_type = Regexp.last_match[:sub_type]
80
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
81
+ end
82
+ else # model
83
+ const = MoneyKit.const_get(klass)
84
+ if const
85
+ if const.respond_to?(:openapi_any_of) # nested anyOf model
86
+ model = const.build(data)
87
+ return model if model
88
+ else
89
+ # raise if data contains keys that are not known to the model
90
+ raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
91
+ model = const.build_from_hash(data)
92
+ return model if model
93
+ end
94
+ end
95
+ end
96
+
97
+ raise # if no match by now, raise
98
+ rescue
99
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
100
+ end
101
+ end
102
+ end
103
+ end