moneykit 0.1.0 → 0.1.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 (30) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +1 -1
  4. data/docs/Body.md +42 -0
  5. data/docs/LinkCommon.md +2 -0
  6. data/docs/LinkProductRefreshWebhook.md +38 -0
  7. data/docs/LinkProductState.md +15 -0
  8. data/docs/LinkResponse.md +2 -0
  9. data/docs/ResponseHandleLinkWebhookEventRequestBodyWebhookPost.md +42 -0
  10. data/docs/TransactionUpdatesAvailableWebhook.md +30 -0
  11. data/lib/moneykit/models/body.rb +104 -0
  12. data/lib/moneykit/models/link_common.rb +18 -1
  13. data/lib/moneykit/models/link_product_refresh_webhook.rb +417 -0
  14. data/lib/moneykit/models/link_product_state.rb +40 -0
  15. data/lib/moneykit/models/link_response.rb +18 -1
  16. data/lib/moneykit/models/response_handle_link_webhook_event_request_body_webhook_post.rb +104 -0
  17. data/lib/moneykit/models/transaction_updates_available_webhook.rb +358 -0
  18. data/lib/moneykit/version.rb +1 -1
  19. data/lib/moneykit.rb +5 -0
  20. data/spec/models/body_spec.rb +21 -0
  21. data/spec/models/link_product_refresh_webhook_spec.rb +108 -0
  22. data/spec/models/link_product_state_spec.rb +30 -0
  23. data/spec/models/response_handle_link_webhook_event_request_body_webhook_post_spec.rb +21 -0
  24. data/spec/models/transaction_updates_available_webhook_spec.rb +84 -0
  25. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/byebug-11.1.3/gem_make.out +5 -5
  26. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/jaro_winkler-1.5.6/gem_make.out +5 -5
  27. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/psych-5.1.1.1/gem_make.out +5 -5
  28. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/racc-1.7.3/gem_make.out +5 -5
  29. data/vendor/bundle/ruby/3.2.0/extensions/x86_64-linux/3.2.0/stringio-3.1.0/gem_make.out +5 -5
  30. metadata +118 -98
@@ -0,0 +1,417 @@
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: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 7.1.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module MoneyKit
17
+ class LinkProductRefreshWebhook
18
+ attr_accessor :webhook_event
19
+
20
+ attr_accessor :webhook_major_version
21
+
22
+ attr_accessor :webhook_minor_version
23
+
24
+ attr_accessor :webhook_idempotency_key
25
+
26
+ attr_accessor :webhook_timestamp
27
+
28
+ attr_accessor :link_id
29
+
30
+ attr_accessor :link_tags
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_event' => :'webhook_event',
66
+ :'webhook_major_version' => :'webhook_major_version',
67
+ :'webhook_minor_version' => :'webhook_minor_version',
68
+ :'webhook_idempotency_key' => :'webhook_idempotency_key',
69
+ :'webhook_timestamp' => :'webhook_timestamp',
70
+ :'link_id' => :'link_id',
71
+ :'link_tags' => :'link_tags',
72
+ :'product' => :'product',
73
+ :'state' => :'state',
74
+ :'state_changed_at' => :'state_changed_at',
75
+ :'error_message' => :'error_message'
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
+ :'webhook_event' => :'String',
88
+ :'webhook_major_version' => :'Integer',
89
+ :'webhook_minor_version' => :'Integer',
90
+ :'webhook_idempotency_key' => :'String',
91
+ :'webhook_timestamp' => :'Time',
92
+ :'link_id' => :'String',
93
+ :'link_tags' => :'Array<String>',
94
+ :'product' => :'Product',
95
+ :'state' => :'LinkProductState',
96
+ :'state_changed_at' => :'Time',
97
+ :'error_message' => :'String'
98
+ }
99
+ end
100
+
101
+ # List of attributes with nullable: true
102
+ def self.openapi_nullable
103
+ Set.new([
104
+ ])
105
+ end
106
+
107
+ # Initializes the object
108
+ # @param [Hash] attributes Model attributes in the form of hash
109
+ def initialize(attributes = {})
110
+ if (!attributes.is_a?(Hash))
111
+ fail ArgumentError, "The input argument (attributes) must be a hash in `MoneyKit::LinkProductRefreshWebhook` initialize method"
112
+ end
113
+
114
+ # check to see if the attribute exists and convert string to symbol for hash key
115
+ attributes = attributes.each_with_object({}) { |(k, v), h|
116
+ if (!self.class.attribute_map.key?(k.to_sym))
117
+ fail ArgumentError, "`#{k}` is not a valid attribute in `MoneyKit::LinkProductRefreshWebhook`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
118
+ end
119
+ h[k.to_sym] = v
120
+ }
121
+
122
+ if attributes.key?(:'webhook_event')
123
+ self.webhook_event = attributes[:'webhook_event']
124
+ else
125
+ self.webhook_event = 'link.product_refresh'
126
+ end
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?(:'product')
167
+ self.product = attributes[:'product']
168
+ else
169
+ self.product = nil
170
+ end
171
+
172
+ if attributes.key?(:'state')
173
+ self.state = attributes[:'state']
174
+ else
175
+ self.state = nil
176
+ end
177
+
178
+ if attributes.key?(:'state_changed_at')
179
+ self.state_changed_at = attributes[:'state_changed_at']
180
+ else
181
+ self.state_changed_at = nil
182
+ end
183
+
184
+ if attributes.key?(:'error_message')
185
+ self.error_message = attributes[:'error_message']
186
+ end
187
+ end
188
+
189
+ # Show invalid properties with the reasons. Usually used together with valid?
190
+ # @return Array for valid properties with the reasons
191
+ def list_invalid_properties
192
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
193
+ invalid_properties = Array.new
194
+ if @webhook_idempotency_key.nil?
195
+ invalid_properties.push('invalid value for "webhook_idempotency_key", webhook_idempotency_key cannot be nil.')
196
+ end
197
+
198
+ if @webhook_timestamp.nil?
199
+ invalid_properties.push('invalid value for "webhook_timestamp", webhook_timestamp cannot be nil.')
200
+ end
201
+
202
+ if @link_id.nil?
203
+ invalid_properties.push('invalid value for "link_id", link_id cannot be nil.')
204
+ end
205
+
206
+ if @link_tags.nil?
207
+ invalid_properties.push('invalid value for "link_tags", link_tags cannot be nil.')
208
+ end
209
+
210
+ if @product.nil?
211
+ invalid_properties.push('invalid value for "product", product cannot be nil.')
212
+ end
213
+
214
+ if @state.nil?
215
+ invalid_properties.push('invalid value for "state", state cannot be nil.')
216
+ end
217
+
218
+ if @state_changed_at.nil?
219
+ invalid_properties.push('invalid value for "state_changed_at", state_changed_at cannot be nil.')
220
+ end
221
+
222
+ invalid_properties
223
+ end
224
+
225
+ # Check to see if the all the properties in the model are valid
226
+ # @return true if the model is valid
227
+ def valid?
228
+ warn '[DEPRECATED] the `valid?` method is obsolete'
229
+ webhook_event_validator = EnumAttributeValidator.new('String', ["link.product_refresh"])
230
+ return false unless webhook_event_validator.valid?(@webhook_event)
231
+ webhook_major_version_validator = EnumAttributeValidator.new('Integer', [1])
232
+ return false unless webhook_major_version_validator.valid?(@webhook_major_version)
233
+ webhook_minor_version_validator = EnumAttributeValidator.new('Integer', [0])
234
+ return false unless webhook_minor_version_validator.valid?(@webhook_minor_version)
235
+ return false if @webhook_idempotency_key.nil?
236
+ return false if @webhook_timestamp.nil?
237
+ return false if @link_id.nil?
238
+ return false if @link_tags.nil?
239
+ return false if @product.nil?
240
+ return false if @state.nil?
241
+ return false if @state_changed_at.nil?
242
+ true
243
+ end
244
+
245
+ # Custom attribute writer method checking allowed values (enum).
246
+ # @param [Object] webhook_event Object to be assigned
247
+ def webhook_event=(webhook_event)
248
+ validator = EnumAttributeValidator.new('String', ["link.product_refresh"])
249
+ unless validator.valid?(webhook_event)
250
+ fail ArgumentError, "invalid value for \"webhook_event\", must be one of #{validator.allowable_values}."
251
+ end
252
+ @webhook_event = webhook_event
253
+ end
254
+
255
+ # Custom attribute writer method checking allowed values (enum).
256
+ # @param [Object] webhook_major_version Object to be assigned
257
+ def webhook_major_version=(webhook_major_version)
258
+ validator = EnumAttributeValidator.new('Integer', [1])
259
+ unless validator.valid?(webhook_major_version)
260
+ fail ArgumentError, "invalid value for \"webhook_major_version\", must be one of #{validator.allowable_values}."
261
+ end
262
+ @webhook_major_version = webhook_major_version
263
+ end
264
+
265
+ # Custom attribute writer method checking allowed values (enum).
266
+ # @param [Object] webhook_minor_version Object to be assigned
267
+ def webhook_minor_version=(webhook_minor_version)
268
+ validator = EnumAttributeValidator.new('Integer', [0])
269
+ unless validator.valid?(webhook_minor_version)
270
+ fail ArgumentError, "invalid value for \"webhook_minor_version\", must be one of #{validator.allowable_values}."
271
+ end
272
+ @webhook_minor_version = webhook_minor_version
273
+ end
274
+
275
+ # Checks equality by comparing each attribute.
276
+ # @param [Object] Object to be compared
277
+ def ==(o)
278
+ return true if self.equal?(o)
279
+ self.class == o.class &&
280
+ webhook_event == o.webhook_event &&
281
+ webhook_major_version == o.webhook_major_version &&
282
+ webhook_minor_version == o.webhook_minor_version &&
283
+ webhook_idempotency_key == o.webhook_idempotency_key &&
284
+ webhook_timestamp == o.webhook_timestamp &&
285
+ link_id == o.link_id &&
286
+ link_tags == o.link_tags &&
287
+ product == o.product &&
288
+ state == o.state &&
289
+ state_changed_at == o.state_changed_at &&
290
+ error_message == o.error_message
291
+ end
292
+
293
+ # @see the `==` method
294
+ # @param [Object] Object to be compared
295
+ def eql?(o)
296
+ self == o
297
+ end
298
+
299
+ # Calculates hash code according to all attributes.
300
+ # @return [Integer] Hash code
301
+ def hash
302
+ [webhook_event, webhook_major_version, webhook_minor_version, webhook_idempotency_key, webhook_timestamp, link_id, link_tags, product, state, state_changed_at, error_message].hash
303
+ end
304
+
305
+ # Builds the object from hash
306
+ # @param [Hash] attributes Model attributes in the form of hash
307
+ # @return [Object] Returns the model itself
308
+ def self.build_from_hash(attributes)
309
+ return nil unless attributes.is_a?(Hash)
310
+ attributes = attributes.transform_keys(&:to_sym)
311
+ transformed_hash = {}
312
+ openapi_types.each_pair do |key, type|
313
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
314
+ transformed_hash["#{key}"] = nil
315
+ elsif type =~ /\AArray<(.*)>/i
316
+ # check to ensure the input is an array given that the attribute
317
+ # is documented as an array but the input is not
318
+ if attributes[attribute_map[key]].is_a?(Array)
319
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
320
+ end
321
+ elsif !attributes[attribute_map[key]].nil?
322
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
323
+ end
324
+ end
325
+ new(transformed_hash)
326
+ end
327
+
328
+ # Deserializes the data based on type
329
+ # @param string type Data type
330
+ # @param string value Value to be deserialized
331
+ # @return [Object] Deserialized data
332
+ def self._deserialize(type, value)
333
+ case type.to_sym
334
+ when :Time
335
+ Time.parse(value)
336
+ when :Date
337
+ Date.parse(value)
338
+ when :String
339
+ value.to_s
340
+ when :Integer
341
+ value.to_i
342
+ when :Float
343
+ value.to_f
344
+ when :Boolean
345
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
346
+ true
347
+ else
348
+ false
349
+ end
350
+ when :Object
351
+ # generic object (usually a Hash), return directly
352
+ value
353
+ when /\AArray<(?<inner_type>.+)>\z/
354
+ inner_type = Regexp.last_match[:inner_type]
355
+ value.map { |v| _deserialize(inner_type, v) }
356
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
357
+ k_type = Regexp.last_match[:k_type]
358
+ v_type = Regexp.last_match[:v_type]
359
+ {}.tap do |hash|
360
+ value.each do |k, v|
361
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
362
+ end
363
+ end
364
+ else # model
365
+ # models (e.g. Pet) or oneOf
366
+ klass = MoneyKit.const_get(type)
367
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
368
+ end
369
+ end
370
+
371
+ # Returns the string representation of the object
372
+ # @return [String] String presentation of the object
373
+ def to_s
374
+ to_hash.to_s
375
+ end
376
+
377
+ # to_body is an alias to to_hash (backward compatibility)
378
+ # @return [Hash] Returns the object in the form of hash
379
+ def to_body
380
+ to_hash
381
+ end
382
+
383
+ # Returns the object in the form of hash
384
+ # @return [Hash] Returns the object in the form of hash
385
+ def to_hash
386
+ hash = {}
387
+ self.class.attribute_map.each_pair do |attr, param|
388
+ value = self.send(attr)
389
+ if value.nil?
390
+ is_nullable = self.class.openapi_nullable.include?(attr)
391
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
392
+ end
393
+
394
+ hash[param] = _to_hash(value)
395
+ end
396
+ hash
397
+ end
398
+
399
+ # Outputs non-array value in the form of hash
400
+ # For object, use to_hash. Otherwise, just return the value
401
+ # @param [Object] value Any valid value
402
+ # @return [Hash] Returns the value in the form of hash
403
+ def _to_hash(value)
404
+ if value.is_a?(Array)
405
+ value.compact.map { |v| _to_hash(v) }
406
+ elsif value.is_a?(Hash)
407
+ {}.tap do |hash|
408
+ value.each { |k, v| hash[k] = _to_hash(v) }
409
+ end
410
+ elsif value.respond_to? :to_hash
411
+ value.to_hash
412
+ else
413
+ value
414
+ end
415
+ end
416
+ end
417
+ end
@@ -0,0 +1,40 @@
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: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 7.1.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module MoneyKit
17
+ class LinkProductState
18
+ COMPLETED = "completed".freeze
19
+ FAILED = "failed".freeze
20
+
21
+ def self.all_vars
22
+ @all_vars ||= [COMPLETED, FAILED].freeze
23
+ end
24
+
25
+ # Builds the enum from string
26
+ # @param [String] The enum value in the form of the string
27
+ # @return [String] The enum value
28
+ def self.build_from_hash(value)
29
+ new.build_from_hash(value)
30
+ end
31
+
32
+ # Builds the enum from string
33
+ # @param [String] The enum value in the form of the string
34
+ # @return [String] The enum value
35
+ def build_from_hash(value)
36
+ return value if LinkProductState.all_vars.include?(value)
37
+ raise "Invalid ENUM value #{value} for class #LinkProductState"
38
+ end
39
+ end
40
+ end
@@ -24,6 +24,9 @@ module MoneyKit
24
24
  # The institution name this link is connected to.
25
25
  attr_accessor :institution_name
26
26
 
27
+ # An avatar image for the link's institution.
28
+ attr_accessor :institution_avatar
29
+
27
30
  attr_accessor :state
28
31
 
29
32
  attr_accessor :error_code
@@ -68,6 +71,7 @@ module MoneyKit
68
71
  :'link_id' => :'link_id',
69
72
  :'institution_id' => :'institution_id',
70
73
  :'institution_name' => :'institution_name',
74
+ :'institution_avatar' => :'institution_avatar',
71
75
  :'state' => :'state',
72
76
  :'error_code' => :'error_code',
73
77
  :'last_synced_at' => :'last_synced_at',
@@ -89,6 +93,7 @@ module MoneyKit
89
93
  :'link_id' => :'String',
90
94
  :'institution_id' => :'String',
91
95
  :'institution_name' => :'String',
96
+ :'institution_avatar' => :'String',
92
97
  :'state' => :'LinkState',
93
98
  :'error_code' => :'PublicLinkError',
94
99
  :'last_synced_at' => :'Time',
@@ -138,6 +143,12 @@ module MoneyKit
138
143
  self.institution_name = nil
139
144
  end
140
145
 
146
+ if attributes.key?(:'institution_avatar')
147
+ self.institution_avatar = attributes[:'institution_avatar']
148
+ else
149
+ self.institution_avatar = nil
150
+ end
151
+
141
152
  if attributes.key?(:'state')
142
153
  self.state = attributes[:'state']
143
154
  else
@@ -192,6 +203,10 @@ module MoneyKit
192
203
  invalid_properties.push('invalid value for "institution_name", institution_name cannot be nil.')
193
204
  end
194
205
 
206
+ if @institution_avatar.nil?
207
+ invalid_properties.push('invalid value for "institution_avatar", institution_avatar cannot be nil.')
208
+ end
209
+
195
210
  if @state.nil?
196
211
  invalid_properties.push('invalid value for "state", state cannot be nil.')
197
212
  end
@@ -214,6 +229,7 @@ module MoneyKit
214
229
  return false if @link_id.nil?
215
230
  return false if @institution_id.nil?
216
231
  return false if @institution_name.nil?
232
+ return false if @institution_avatar.nil?
217
233
  return false if @state.nil?
218
234
  return false if @products.nil?
219
235
  return false if @provider.nil?
@@ -228,6 +244,7 @@ module MoneyKit
228
244
  link_id == o.link_id &&
229
245
  institution_id == o.institution_id &&
230
246
  institution_name == o.institution_name &&
247
+ institution_avatar == o.institution_avatar &&
231
248
  state == o.state &&
232
249
  error_code == o.error_code &&
233
250
  last_synced_at == o.last_synced_at &&
@@ -246,7 +263,7 @@ module MoneyKit
246
263
  # Calculates hash code according to all attributes.
247
264
  # @return [Integer] Hash code
248
265
  def hash
249
- [link_id, institution_id, institution_name, state, error_code, last_synced_at, tags, products, provider, webhook].hash
266
+ [link_id, institution_id, institution_name, institution_avatar, state, error_code, last_synced_at, tags, products, provider, webhook].hash
250
267
  end
251
268
 
252
269
  # Builds the object from hash
@@ -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: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 7.1.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module MoneyKit
17
+ module ResponseHandleLinkWebhookEventRequestBodyWebhookPost
18
+ class << self
19
+ # List of class defined in anyOf (OpenAPI v3)
20
+ def openapi_any_of
21
+ [
22
+ :'LinkProductRefreshWebhook',
23
+ :'LinkStateChangedWebhook',
24
+ :'TransactionUpdatesAvailableWebhook'
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 unless (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