carbon_ruby_sdk 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +15 -19
  3. data/README.md +21 -7
  4. data/lib/carbon_ruby_sdk/api/files_api.rb +15 -4
  5. data/lib/carbon_ruby_sdk/api/integrations_api.rb +8 -8
  6. data/lib/carbon_ruby_sdk/models/file_sync_config.rb +11 -1
  7. data/lib/carbon_ruby_sdk/models/file_sync_config_nullable.rb +11 -1
  8. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +2 -2
  9. data/lib/carbon_ruby_sdk/models/object_type.rb +42 -0
  10. data/lib/carbon_ruby_sdk/models/sent_webhook_payload.rb +276 -0
  11. data/lib/carbon_ruby_sdk/models/sent_webhook_payload_object.rb +235 -0
  12. data/lib/carbon_ruby_sdk/models/sent_webhook_payload_object_additional_information.rb +101 -0
  13. data/lib/carbon_ruby_sdk/models/sent_webhook_payload_object_object_id.rb +103 -0
  14. data/lib/carbon_ruby_sdk/models/sent_webhook_request_body.rb +215 -0
  15. data/lib/carbon_ruby_sdk/models/sync_files_request.rb +1 -1
  16. data/lib/carbon_ruby_sdk/models/sync_options.rb +1 -1
  17. data/lib/carbon_ruby_sdk/models/transcription_service.rb +36 -0
  18. data/lib/carbon_ruby_sdk/models/transcription_service_nullable.rb +36 -0
  19. data/lib/carbon_ruby_sdk/models/upload_file_from_url_input.rb +11 -1
  20. data/lib/carbon_ruby_sdk/version.rb +1 -1
  21. data/lib/carbon_ruby_sdk.rb +8 -0
  22. data/spec/api/files_api_spec.rb +1 -0
  23. data/spec/models/file_sync_config_nullable_spec.rb +6 -0
  24. data/spec/models/file_sync_config_spec.rb +6 -0
  25. data/spec/models/object_type_spec.rb +22 -0
  26. data/spec/models/sent_webhook_payload_object_additional_information_spec.rb +25 -0
  27. data/spec/models/sent_webhook_payload_object_object_id_spec.rb +25 -0
  28. data/spec/models/sent_webhook_payload_object_spec.rb +40 -0
  29. data/spec/models/sent_webhook_payload_spec.rb +50 -0
  30. data/spec/models/sent_webhook_request_body_spec.rb +28 -0
  31. data/spec/models/transcription_service_nullable_spec.rb +22 -0
  32. data/spec/models/transcription_service_spec.rb +22 -0
  33. data/spec/models/upload_file_from_url_input_spec.rb +6 -0
  34. metadata +27 -3
@@ -0,0 +1,276 @@
1
+ =begin
2
+ #Carbon
3
+
4
+ #Connect external data to LLMs, no matter the source.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ =end
8
+
9
+ require 'date'
10
+ require 'time'
11
+
12
+ module Carbon
13
+ class SentWebhookPayload
14
+ attr_accessor :webhook_type
15
+
16
+ attr_accessor :customer_id
17
+
18
+ attr_accessor :timestamp
19
+
20
+ attr_accessor :object
21
+
22
+ class EnumAttributeValidator
23
+ attr_reader :datatype
24
+ attr_reader :allowable_values
25
+
26
+ def initialize(datatype, allowable_values)
27
+ @allowable_values = allowable_values.map do |value|
28
+ case datatype.to_s
29
+ when /Integer/i
30
+ value.to_i
31
+ when /Float/i
32
+ value.to_f
33
+ else
34
+ value
35
+ end
36
+ end
37
+ end
38
+
39
+ def valid?(value)
40
+ !value || allowable_values.include?(value)
41
+ end
42
+ end
43
+
44
+ # Attribute mapping from ruby-style variable name to JSON key.
45
+ def self.attribute_map
46
+ {
47
+ :'webhook_type' => :'webhook_type',
48
+ :'customer_id' => :'customer_id',
49
+ :'timestamp' => :'timestamp',
50
+ :'object' => :'object'
51
+ }
52
+ end
53
+
54
+ # Returns all the JSON keys this model knows about
55
+ def self.acceptable_attributes
56
+ attribute_map.values
57
+ end
58
+
59
+ # Attribute type mapping.
60
+ def self.openapi_types
61
+ {
62
+ :'webhook_type' => :'String',
63
+ :'customer_id' => :'String',
64
+ :'timestamp' => :'String',
65
+ :'object' => :'SentWebhookPayloadObject'
66
+ }
67
+ end
68
+
69
+ # List of attributes with nullable: true
70
+ def self.openapi_nullable
71
+ Set.new([
72
+ ])
73
+ end
74
+
75
+ # Initializes the object
76
+ # @param [Hash] attributes Model attributes in the form of hash
77
+ def initialize(attributes = {})
78
+ if (!attributes.is_a?(Hash))
79
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::SentWebhookPayload` initialize method"
80
+ end
81
+
82
+ # check to see if the attribute exists and convert string to symbol for hash key
83
+ attributes = attributes.each_with_object({}) { |(k, v), h|
84
+ if (!self.class.attribute_map.key?(k.to_sym))
85
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::SentWebhookPayload`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
86
+ end
87
+ h[k.to_sym] = v
88
+ }
89
+
90
+ if attributes.key?(:'webhook_type')
91
+ self.webhook_type = attributes[:'webhook_type']
92
+ end
93
+
94
+ if attributes.key?(:'customer_id')
95
+ self.customer_id = attributes[:'customer_id']
96
+ end
97
+
98
+ if attributes.key?(:'timestamp')
99
+ self.timestamp = attributes[:'timestamp']
100
+ end
101
+
102
+ if attributes.key?(:'object')
103
+ self.object = attributes[:'object']
104
+ end
105
+ end
106
+
107
+ # Show invalid properties with the reasons. Usually used together with valid?
108
+ # @return Array for valid properties with the reasons
109
+ def list_invalid_properties
110
+ invalid_properties = Array.new
111
+ invalid_properties
112
+ end
113
+
114
+ # Check to see if the all the properties in the model are valid
115
+ # @return true if the model is valid
116
+ def valid?
117
+ webhook_type_validator = EnumAttributeValidator.new('String', ["ALL_UPLOADED_FILES_QUEUED", "CHECKUP", "DATA_SOURCE_READY", "FILES_CREATED", "FILES_SKIPPED", "FILE_DELETED", "FILE_ERROR", "FILE_READY", "FILE_STATISTICS_AGGREGATED", "FILE_SYNC_LIMIT_REACHED", "ORGANIZATION_USER_DELETED", "RATE_LIMIT_ERROR", "SPARSE_VECTOR_QUEUE_STATUS", "WEBPAGE_ERROR", "WEBPAGE_READY", "WEBSCRAPE_URLS_READY"])
118
+ return false unless webhook_type_validator.valid?(@webhook_type)
119
+ true
120
+ end
121
+
122
+ # Custom attribute writer method checking allowed values (enum).
123
+ # @param [Object] webhook_type Object to be assigned
124
+ def webhook_type=(webhook_type)
125
+ validator = EnumAttributeValidator.new('String', ["ALL_UPLOADED_FILES_QUEUED", "CHECKUP", "DATA_SOURCE_READY", "FILES_CREATED", "FILES_SKIPPED", "FILE_DELETED", "FILE_ERROR", "FILE_READY", "FILE_STATISTICS_AGGREGATED", "FILE_SYNC_LIMIT_REACHED", "ORGANIZATION_USER_DELETED", "RATE_LIMIT_ERROR", "SPARSE_VECTOR_QUEUE_STATUS", "WEBPAGE_ERROR", "WEBPAGE_READY", "WEBSCRAPE_URLS_READY"])
126
+ unless validator.valid?(webhook_type)
127
+ fail ArgumentError, "invalid value for \"webhook_type\", must be one of #{validator.allowable_values}."
128
+ end
129
+ @webhook_type = webhook_type
130
+ end
131
+
132
+ # Checks equality by comparing each attribute.
133
+ # @param [Object] Object to be compared
134
+ def ==(o)
135
+ return true if self.equal?(o)
136
+ self.class == o.class &&
137
+ webhook_type == o.webhook_type &&
138
+ customer_id == o.customer_id &&
139
+ timestamp == o.timestamp &&
140
+ object == o.object
141
+ end
142
+
143
+ # @see the `==` method
144
+ # @param [Object] Object to be compared
145
+ def eql?(o)
146
+ self == o
147
+ end
148
+
149
+ # Calculates hash code according to all attributes.
150
+ # @return [Integer] Hash code
151
+ def hash
152
+ [webhook_type, customer_id, timestamp, object].hash
153
+ end
154
+
155
+ # Builds the object from hash
156
+ # @param [Hash] attributes Model attributes in the form of hash
157
+ # @return [Object] Returns the model itself
158
+ def self.build_from_hash(attributes)
159
+ new.build_from_hash(attributes)
160
+ end
161
+
162
+ # Builds the object from hash
163
+ # @param [Hash] attributes Model attributes in the form of hash
164
+ # @return [Object] Returns the model itself
165
+ def build_from_hash(attributes)
166
+ return nil unless attributes.is_a?(Hash)
167
+ attributes = attributes.transform_keys(&:to_sym)
168
+ self.class.openapi_types.each_pair do |key, type|
169
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
170
+ self.send("#{key}=", nil)
171
+ elsif type =~ /\AArray<(.*)>/i
172
+ # check to ensure the input is an array given that the attribute
173
+ # is documented as an array but the input is not
174
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
175
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
176
+ end
177
+ elsif !attributes[self.class.attribute_map[key]].nil?
178
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
179
+ end
180
+ end
181
+
182
+ self
183
+ end
184
+
185
+ # Deserializes the data based on type
186
+ # @param string type Data type
187
+ # @param string value Value to be deserialized
188
+ # @return [Object] Deserialized data
189
+ def _deserialize(type, value)
190
+ case type.to_sym
191
+ when :Time
192
+ Time.parse(value)
193
+ when :Date
194
+ Date.parse(value)
195
+ when :String
196
+ value.to_s
197
+ when :Integer
198
+ value.to_i
199
+ when :Float
200
+ value.to_f
201
+ when :Boolean
202
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
203
+ true
204
+ else
205
+ false
206
+ end
207
+ when :Object
208
+ # generic object (usually a Hash), return directly
209
+ value
210
+ when /\AArray<(?<inner_type>.+)>\z/
211
+ inner_type = Regexp.last_match[:inner_type]
212
+ value.map { |v| _deserialize(inner_type, v) }
213
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
214
+ k_type = Regexp.last_match[:k_type]
215
+ v_type = Regexp.last_match[:v_type]
216
+ {}.tap do |hash|
217
+ value.each do |k, v|
218
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
219
+ end
220
+ end
221
+ else # model
222
+ # models (e.g. Pet) or oneOf
223
+ klass = Carbon.const_get(type)
224
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
225
+ end
226
+ end
227
+
228
+ # Returns the string representation of the object
229
+ # @return [String] String presentation of the object
230
+ def to_s
231
+ to_hash.to_s
232
+ end
233
+
234
+ # to_body is an alias to to_hash (backward compatibility)
235
+ # @return [Hash] Returns the object in the form of hash
236
+ def to_body
237
+ to_hash
238
+ end
239
+
240
+ # Returns the object in the form of hash
241
+ # @return [Hash] Returns the object in the form of hash
242
+ def to_hash
243
+ hash = {}
244
+ self.class.attribute_map.each_pair do |attr, param|
245
+ value = self.send(attr)
246
+ if value.nil?
247
+ is_nullable = self.class.openapi_nullable.include?(attr)
248
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
249
+ end
250
+
251
+ hash[param] = _to_hash(value)
252
+ end
253
+ hash
254
+ end
255
+
256
+ # Outputs non-array value in the form of hash
257
+ # For object, use to_hash. Otherwise, just return the value
258
+ # @param [Object] value Any valid value
259
+ # @return [Hash] Returns the value in the form of hash
260
+ def _to_hash(value)
261
+ if value.is_a?(Array)
262
+ value.compact.map { |v| _to_hash(v) }
263
+ elsif value.is_a?(Hash)
264
+ {}.tap do |hash|
265
+ value.each { |k, v| hash[k] = _to_hash(v) }
266
+ end
267
+ elsif value.respond_to? :to_hash
268
+ value.to_hash
269
+ else
270
+ value
271
+ end
272
+ end
273
+
274
+ end
275
+
276
+ end
@@ -0,0 +1,235 @@
1
+ =begin
2
+ #Carbon
3
+
4
+ #Connect external data to LLMs, no matter the source.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ =end
8
+
9
+ require 'date'
10
+ require 'time'
11
+
12
+ module Carbon
13
+ class SentWebhookPayloadObject
14
+ attr_accessor :object_type
15
+
16
+ attr_accessor :object_id
17
+
18
+ attr_accessor :additional_information
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'object_type' => :'object_type',
24
+ :'object_id' => :'object_id',
25
+ :'additional_information' => :'additional_information'
26
+ }
27
+ end
28
+
29
+ # Returns all the JSON keys this model knows about
30
+ def self.acceptable_attributes
31
+ attribute_map.values
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ :'object_type' => :'ObjectType',
38
+ :'object_id' => :'SentWebhookPayloadObjectObjectId',
39
+ :'additional_information' => :'SentWebhookPayloadObjectAdditionalInformation'
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([
46
+ :'object_id',
47
+ :'additional_information'
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::SentWebhookPayloadObject` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::SentWebhookPayloadObject`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'object_type')
67
+ self.object_type = attributes[:'object_type']
68
+ end
69
+
70
+ if attributes.key?(:'object_id')
71
+ self.object_id = attributes[:'object_id']
72
+ end
73
+
74
+ if attributes.key?(:'additional_information')
75
+ self.additional_information = attributes[:'additional_information']
76
+ end
77
+ end
78
+
79
+ # Show invalid properties with the reasons. Usually used together with valid?
80
+ # @return Array for valid properties with the reasons
81
+ def list_invalid_properties
82
+ invalid_properties = Array.new
83
+ invalid_properties
84
+ end
85
+
86
+ # Check to see if the all the properties in the model are valid
87
+ # @return true if the model is valid
88
+ def valid?
89
+ true
90
+ end
91
+
92
+ # Checks equality by comparing each attribute.
93
+ # @param [Object] Object to be compared
94
+ def ==(o)
95
+ return true if self.equal?(o)
96
+ self.class == o.class &&
97
+ object_type == o.object_type &&
98
+ object_id == o.object_id &&
99
+ additional_information == o.additional_information
100
+ end
101
+
102
+ # @see the `==` method
103
+ # @param [Object] Object to be compared
104
+ def eql?(o)
105
+ self == o
106
+ end
107
+
108
+ # Calculates hash code according to all attributes.
109
+ # @return [Integer] Hash code
110
+ def hash
111
+ [object_type, object_id, additional_information].hash
112
+ end
113
+
114
+ # Builds the object from hash
115
+ # @param [Hash] attributes Model attributes in the form of hash
116
+ # @return [Object] Returns the model itself
117
+ def self.build_from_hash(attributes)
118
+ new.build_from_hash(attributes)
119
+ end
120
+
121
+ # Builds the object from hash
122
+ # @param [Hash] attributes Model attributes in the form of hash
123
+ # @return [Object] Returns the model itself
124
+ def build_from_hash(attributes)
125
+ return nil unless attributes.is_a?(Hash)
126
+ attributes = attributes.transform_keys(&:to_sym)
127
+ self.class.openapi_types.each_pair do |key, type|
128
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
129
+ self.send("#{key}=", nil)
130
+ elsif type =~ /\AArray<(.*)>/i
131
+ # check to ensure the input is an array given that the attribute
132
+ # is documented as an array but the input is not
133
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
134
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
135
+ end
136
+ elsif !attributes[self.class.attribute_map[key]].nil?
137
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
138
+ end
139
+ end
140
+
141
+ self
142
+ end
143
+
144
+ # Deserializes the data based on type
145
+ # @param string type Data type
146
+ # @param string value Value to be deserialized
147
+ # @return [Object] Deserialized data
148
+ def _deserialize(type, value)
149
+ case type.to_sym
150
+ when :Time
151
+ Time.parse(value)
152
+ when :Date
153
+ Date.parse(value)
154
+ when :String
155
+ value.to_s
156
+ when :Integer
157
+ value.to_i
158
+ when :Float
159
+ value.to_f
160
+ when :Boolean
161
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
162
+ true
163
+ else
164
+ false
165
+ end
166
+ when :Object
167
+ # generic object (usually a Hash), return directly
168
+ value
169
+ when /\AArray<(?<inner_type>.+)>\z/
170
+ inner_type = Regexp.last_match[:inner_type]
171
+ value.map { |v| _deserialize(inner_type, v) }
172
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
173
+ k_type = Regexp.last_match[:k_type]
174
+ v_type = Regexp.last_match[:v_type]
175
+ {}.tap do |hash|
176
+ value.each do |k, v|
177
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
178
+ end
179
+ end
180
+ else # model
181
+ # models (e.g. Pet) or oneOf
182
+ klass = Carbon.const_get(type)
183
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
184
+ end
185
+ end
186
+
187
+ # Returns the string representation of the object
188
+ # @return [String] String presentation of the object
189
+ def to_s
190
+ to_hash.to_s
191
+ end
192
+
193
+ # to_body is an alias to to_hash (backward compatibility)
194
+ # @return [Hash] Returns the object in the form of hash
195
+ def to_body
196
+ to_hash
197
+ end
198
+
199
+ # Returns the object in the form of hash
200
+ # @return [Hash] Returns the object in the form of hash
201
+ def to_hash
202
+ hash = {}
203
+ self.class.attribute_map.each_pair do |attr, param|
204
+ value = self.send(attr)
205
+ if value.nil?
206
+ is_nullable = self.class.openapi_nullable.include?(attr)
207
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
208
+ end
209
+
210
+ hash[param] = _to_hash(value)
211
+ end
212
+ hash
213
+ end
214
+
215
+ # Outputs non-array value in the form of hash
216
+ # For object, use to_hash. Otherwise, just return the value
217
+ # @param [Object] value Any valid value
218
+ # @return [Hash] Returns the value in the form of hash
219
+ def _to_hash(value)
220
+ if value.is_a?(Array)
221
+ value.compact.map { |v| _to_hash(v) }
222
+ elsif value.is_a?(Hash)
223
+ {}.tap do |hash|
224
+ value.each { |k, v| hash[k] = _to_hash(v) }
225
+ end
226
+ elsif value.respond_to? :to_hash
227
+ value.to_hash
228
+ else
229
+ value
230
+ end
231
+ end
232
+
233
+ end
234
+
235
+ end
@@ -0,0 +1,101 @@
1
+ =begin
2
+ #Carbon
3
+
4
+ #Connect external data to LLMs, no matter the source.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ =end
8
+
9
+ require 'date'
10
+ require 'time'
11
+
12
+ module Carbon
13
+ module SentWebhookPayloadObjectAdditionalInformation
14
+ class << self
15
+ # List of class defined in oneOf (OpenAPI v3)
16
+ def openapi_one_of
17
+ [
18
+ :'Object',
19
+ :'String'
20
+ ]
21
+ end
22
+
23
+ # Builds the object
24
+ # @param [Mixed] Data to be matched against the list of oneOf items
25
+ # @return [Object] Returns the model or the data itself
26
+ def build(data)
27
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
28
+ # Note:
29
+ # - We do not attempt to check whether exactly one item matches.
30
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
31
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
32
+ # - TODO: scalar values are de facto behaving as if they were nullable.
33
+ # - TODO: logging when debugging is set.
34
+ openapi_one_of.each do |klass|
35
+ begin
36
+ next if klass == :AnyType # "nullable: true"
37
+ typed_data = find_and_cast_into_type(klass, data)
38
+ return typed_data if typed_data
39
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
40
+ end
41
+ end
42
+
43
+ openapi_one_of.include?(:AnyType) ? data : nil
44
+ end
45
+
46
+ private
47
+
48
+ SchemaMismatchError = Class.new(StandardError)
49
+
50
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
51
+ def find_and_cast_into_type(klass, data)
52
+ return if data.nil?
53
+
54
+ case klass.to_s
55
+ when 'Boolean'
56
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
57
+ when 'Float'
58
+ return data if data.instance_of?(Float)
59
+ when 'Integer'
60
+ return data if data.instance_of?(Integer)
61
+ when 'Time'
62
+ return Time.parse(data)
63
+ when 'Date'
64
+ return Date.parse(data)
65
+ when 'String'
66
+ return data if data.instance_of?(String)
67
+ when 'Object' # "type: object"
68
+ return data if data.instance_of?(Hash)
69
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
70
+ if data.instance_of?(Array)
71
+ sub_type = Regexp.last_match[:sub_type]
72
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
73
+ end
74
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
75
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
76
+ sub_type = Regexp.last_match[:sub_type]
77
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
78
+ end
79
+ else # model
80
+ const = Carbon.const_get(klass)
81
+ if const
82
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
83
+ model = const.build(data)
84
+ return model if model
85
+ else
86
+ # raise if data contains keys that are not known to the model
87
+ raise unless (data.keys - const.acceptable_attributes).empty?
88
+ model = const.build_from_hash(data)
89
+ return model if model && model.valid?
90
+ end
91
+ end
92
+ end
93
+
94
+ raise # if no match by now, raise
95
+ rescue
96
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
97
+ end
98
+ end
99
+ end
100
+
101
+ end