carbon_ruby_sdk 0.2.29 → 0.2.30

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -7
  3. data/README.md +42 -6
  4. data/lib/carbon_ruby_sdk/api/embeddings_api.rb +2 -2
  5. data/lib/carbon_ruby_sdk/api/files_api.rb +21 -6
  6. data/lib/carbon_ruby_sdk/api/integrations_api.rb +12 -8
  7. data/lib/carbon_ruby_sdk/api/utilities_api.rb +6 -2
  8. data/lib/carbon_ruby_sdk/models/authentication_property.rb +62 -5
  9. data/lib/carbon_ruby_sdk/models/auto_synced_source_types_property_inner.rb +226 -0
  10. data/lib/carbon_ruby_sdk/models/data_source_type.rb +2 -1
  11. data/lib/carbon_ruby_sdk/models/data_source_type_nullable.rb +2 -1
  12. data/lib/carbon_ruby_sdk/models/external_data_source_type.rb +2 -1
  13. data/lib/carbon_ruby_sdk/models/file_formats.rb +2 -1
  14. data/lib/carbon_ruby_sdk/models/file_formats_nullable.rb +2 -1
  15. data/lib/carbon_ruby_sdk/models/file_sync_config.rb +17 -5
  16. data/lib/carbon_ruby_sdk/models/file_sync_config_nullable.rb +17 -5
  17. data/lib/carbon_ruby_sdk/models/get_embedding_documents_body.rb +1 -1
  18. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +16 -6
  19. data/lib/carbon_ruby_sdk/models/organization_user_files_to_sync_filters.rb +1 -1
  20. data/lib/carbon_ruby_sdk/models/raw_text_input.rb +16 -4
  21. data/lib/carbon_ruby_sdk/models/service_now_authentication.rb +296 -0
  22. data/lib/carbon_ruby_sdk/models/service_now_credentials.rb +262 -0
  23. data/lib/carbon_ruby_sdk/models/service_now_credentials_nullable.rb +263 -0
  24. data/lib/carbon_ruby_sdk/models/service_now_file_types.rb +37 -0
  25. data/lib/carbon_ruby_sdk/models/sitemap_scrape_request.rb +17 -5
  26. data/lib/carbon_ruby_sdk/models/sync_files_request.rb +1 -1
  27. data/lib/carbon_ruby_sdk/models/sync_options.rb +1 -1
  28. data/lib/carbon_ruby_sdk/models/upload_file_from_url_input.rb +16 -4
  29. data/lib/carbon_ruby_sdk/models/webscrape_request.rb +17 -5
  30. data/lib/carbon_ruby_sdk/version.rb +1 -1
  31. data/lib/carbon_ruby_sdk.rb +5 -0
  32. data/spec/api/files_api_spec.rb +1 -0
  33. data/spec/models/authentication_property_spec.rb +24 -0
  34. data/spec/models/auto_synced_source_types_property_inner_spec.rb +22 -0
  35. data/spec/models/file_sync_config_nullable_spec.rb +6 -0
  36. data/spec/models/file_sync_config_spec.rb +6 -0
  37. data/spec/models/o_auth_url_request_spec.rb +6 -0
  38. data/spec/models/raw_text_input_spec.rb +6 -0
  39. data/spec/models/service_now_authentication_spec.rb +64 -0
  40. data/spec/models/service_now_credentials_nullable_spec.rb +46 -0
  41. data/spec/models/service_now_credentials_spec.rb +46 -0
  42. data/spec/models/service_now_file_types_spec.rb +22 -0
  43. data/spec/models/sitemap_scrape_request_spec.rb +6 -0
  44. data/spec/models/upload_file_from_url_input_spec.rb +6 -0
  45. data/spec/models/webscrape_request_spec.rb +6 -0
  46. metadata +165 -150
@@ -29,6 +29,9 @@ module Carbon
29
29
 
30
30
  attr_accessor :cold_storage_params
31
31
 
32
+ # If this flag is enabled, the file will be chunked and stored with Carbon, but no embeddings will be generated. This overrides the skip_embedding_generation flag.
33
+ attr_accessor :generate_chunks_only
34
+
32
35
  # Attribute mapping from ruby-style variable name to JSON key.
33
36
  def self.attribute_map
34
37
  {
@@ -40,7 +43,8 @@ module Carbon
40
43
  :'overwrite_file_id' => :'overwrite_file_id',
41
44
  :'embedding_model' => :'embedding_model',
42
45
  :'generate_sparse_vectors' => :'generate_sparse_vectors',
43
- :'cold_storage_params' => :'cold_storage_params'
46
+ :'cold_storage_params' => :'cold_storage_params',
47
+ :'generate_chunks_only' => :'generate_chunks_only'
44
48
  }
45
49
  end
46
50
 
@@ -60,7 +64,8 @@ module Carbon
60
64
  :'overwrite_file_id' => :'Integer',
61
65
  :'embedding_model' => :'EmbeddingGeneratorsNullable',
62
66
  :'generate_sparse_vectors' => :'Boolean',
63
- :'cold_storage_params' => :'ColdStorageProps'
67
+ :'cold_storage_params' => :'ColdStorageProps',
68
+ :'generate_chunks_only' => :'Boolean'
64
69
  }
65
70
  end
66
71
 
@@ -132,6 +137,12 @@ module Carbon
132
137
  if attributes.key?(:'cold_storage_params')
133
138
  self.cold_storage_params = attributes[:'cold_storage_params']
134
139
  end
140
+
141
+ if attributes.key?(:'generate_chunks_only')
142
+ self.generate_chunks_only = attributes[:'generate_chunks_only']
143
+ else
144
+ self.generate_chunks_only = false
145
+ end
135
146
  end
136
147
 
137
148
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -184,7 +195,8 @@ module Carbon
184
195
  overwrite_file_id == o.overwrite_file_id &&
185
196
  embedding_model == o.embedding_model &&
186
197
  generate_sparse_vectors == o.generate_sparse_vectors &&
187
- cold_storage_params == o.cold_storage_params
198
+ cold_storage_params == o.cold_storage_params &&
199
+ generate_chunks_only == o.generate_chunks_only
188
200
  end
189
201
 
190
202
  # @see the `==` method
@@ -196,7 +208,7 @@ module Carbon
196
208
  # Calculates hash code according to all attributes.
197
209
  # @return [Integer] Hash code
198
210
  def hash
199
- [contents, name, chunk_size, chunk_overlap, skip_embedding_generation, overwrite_file_id, embedding_model, generate_sparse_vectors, cold_storage_params].hash
211
+ [contents, name, chunk_size, chunk_overlap, skip_embedding_generation, overwrite_file_id, embedding_model, generate_sparse_vectors, cold_storage_params, generate_chunks_only].hash
200
212
  end
201
213
 
202
214
  # Builds the object from hash
@@ -0,0 +1,296 @@
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 ServiceNowAuthentication
14
+ attr_accessor :source
15
+
16
+ attr_accessor :access_token
17
+
18
+ attr_accessor :refresh_token
19
+
20
+ attr_accessor :instance_subdomain
21
+
22
+ attr_accessor :client_id
23
+
24
+ attr_accessor :client_secret
25
+
26
+ attr_accessor :redirect_uri
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'source' => :'source',
32
+ :'access_token' => :'access_token',
33
+ :'refresh_token' => :'refresh_token',
34
+ :'instance_subdomain' => :'instance_subdomain',
35
+ :'client_id' => :'client_id',
36
+ :'client_secret' => :'client_secret',
37
+ :'redirect_uri' => :'redirect_uri'
38
+ }
39
+ end
40
+
41
+ # Returns all the JSON keys this model knows about
42
+ def self.acceptable_attributes
43
+ attribute_map.values
44
+ end
45
+
46
+ # Attribute type mapping.
47
+ def self.openapi_types
48
+ {
49
+ :'source' => :'Object',
50
+ :'access_token' => :'String',
51
+ :'refresh_token' => :'String',
52
+ :'instance_subdomain' => :'String',
53
+ :'client_id' => :'String',
54
+ :'client_secret' => :'String',
55
+ :'redirect_uri' => :'String'
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new([
62
+ :'source',
63
+ :'refresh_token',
64
+ ])
65
+ end
66
+
67
+ # Initializes the object
68
+ # @param [Hash] attributes Model attributes in the form of hash
69
+ def initialize(attributes = {})
70
+ if (!attributes.is_a?(Hash))
71
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::ServiceNowAuthentication` initialize method"
72
+ end
73
+
74
+ # check to see if the attribute exists and convert string to symbol for hash key
75
+ attributes = attributes.each_with_object({}) { |(k, v), h|
76
+ if (!self.class.attribute_map.key?(k.to_sym))
77
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::ServiceNowAuthentication`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
78
+ end
79
+ h[k.to_sym] = v
80
+ }
81
+
82
+ if attributes.key?(:'source')
83
+ self.source = attributes[:'source']
84
+ end
85
+
86
+ if attributes.key?(:'access_token')
87
+ self.access_token = attributes[:'access_token']
88
+ end
89
+
90
+ if attributes.key?(:'refresh_token')
91
+ self.refresh_token = attributes[:'refresh_token']
92
+ end
93
+
94
+ if attributes.key?(:'instance_subdomain')
95
+ self.instance_subdomain = attributes[:'instance_subdomain']
96
+ end
97
+
98
+ if attributes.key?(:'client_id')
99
+ self.client_id = attributes[:'client_id']
100
+ end
101
+
102
+ if attributes.key?(:'client_secret')
103
+ self.client_secret = attributes[:'client_secret']
104
+ end
105
+
106
+ if attributes.key?(:'redirect_uri')
107
+ self.redirect_uri = attributes[:'redirect_uri']
108
+ end
109
+ end
110
+
111
+ # Show invalid properties with the reasons. Usually used together with valid?
112
+ # @return Array for valid properties with the reasons
113
+ def list_invalid_properties
114
+ invalid_properties = Array.new
115
+ if @access_token.nil?
116
+ invalid_properties.push('invalid value for "access_token", access_token cannot be nil.')
117
+ end
118
+
119
+ if @instance_subdomain.nil?
120
+ invalid_properties.push('invalid value for "instance_subdomain", instance_subdomain cannot be nil.')
121
+ end
122
+
123
+ if @client_id.nil?
124
+ invalid_properties.push('invalid value for "client_id", client_id cannot be nil.')
125
+ end
126
+
127
+ if @client_secret.nil?
128
+ invalid_properties.push('invalid value for "client_secret", client_secret cannot be nil.')
129
+ end
130
+
131
+ if @redirect_uri.nil?
132
+ invalid_properties.push('invalid value for "redirect_uri", redirect_uri cannot be nil.')
133
+ end
134
+
135
+ invalid_properties
136
+ end
137
+
138
+ # Check to see if the all the properties in the model are valid
139
+ # @return true if the model is valid
140
+ def valid?
141
+ return false if @access_token.nil?
142
+ return false if @instance_subdomain.nil?
143
+ return false if @client_id.nil?
144
+ return false if @client_secret.nil?
145
+ return false if @redirect_uri.nil?
146
+ true
147
+ end
148
+
149
+ # Checks equality by comparing each attribute.
150
+ # @param [Object] Object to be compared
151
+ def ==(o)
152
+ return true if self.equal?(o)
153
+ self.class == o.class &&
154
+ source == o.source &&
155
+ access_token == o.access_token &&
156
+ refresh_token == o.refresh_token &&
157
+ instance_subdomain == o.instance_subdomain &&
158
+ client_id == o.client_id &&
159
+ client_secret == o.client_secret &&
160
+ redirect_uri == o.redirect_uri
161
+ end
162
+
163
+ # @see the `==` method
164
+ # @param [Object] Object to be compared
165
+ def eql?(o)
166
+ self == o
167
+ end
168
+
169
+ # Calculates hash code according to all attributes.
170
+ # @return [Integer] Hash code
171
+ def hash
172
+ [source, access_token, refresh_token, instance_subdomain, client_id, client_secret, redirect_uri].hash
173
+ end
174
+
175
+ # Builds the object from hash
176
+ # @param [Hash] attributes Model attributes in the form of hash
177
+ # @return [Object] Returns the model itself
178
+ def self.build_from_hash(attributes)
179
+ new.build_from_hash(attributes)
180
+ end
181
+
182
+ # Builds the object from hash
183
+ # @param [Hash] attributes Model attributes in the form of hash
184
+ # @return [Object] Returns the model itself
185
+ def build_from_hash(attributes)
186
+ return nil unless attributes.is_a?(Hash)
187
+ attributes = attributes.transform_keys(&:to_sym)
188
+ self.class.openapi_types.each_pair do |key, type|
189
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
190
+ self.send("#{key}=", nil)
191
+ elsif type =~ /\AArray<(.*)>/i
192
+ # check to ensure the input is an array given that the attribute
193
+ # is documented as an array but the input is not
194
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
195
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
196
+ end
197
+ elsif !attributes[self.class.attribute_map[key]].nil?
198
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
199
+ end
200
+ end
201
+
202
+ self
203
+ end
204
+
205
+ # Deserializes the data based on type
206
+ # @param string type Data type
207
+ # @param string value Value to be deserialized
208
+ # @return [Object] Deserialized data
209
+ def _deserialize(type, value)
210
+ case type.to_sym
211
+ when :Time
212
+ Time.parse(value)
213
+ when :Date
214
+ Date.parse(value)
215
+ when :String
216
+ value.to_s
217
+ when :Integer
218
+ value.to_i
219
+ when :Float
220
+ value.to_f
221
+ when :Boolean
222
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
223
+ true
224
+ else
225
+ false
226
+ end
227
+ when :Object
228
+ # generic object (usually a Hash), return directly
229
+ value
230
+ when /\AArray<(?<inner_type>.+)>\z/
231
+ inner_type = Regexp.last_match[:inner_type]
232
+ value.map { |v| _deserialize(inner_type, v) }
233
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
234
+ k_type = Regexp.last_match[:k_type]
235
+ v_type = Regexp.last_match[:v_type]
236
+ {}.tap do |hash|
237
+ value.each do |k, v|
238
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
239
+ end
240
+ end
241
+ else # model
242
+ # models (e.g. Pet) or oneOf
243
+ klass = Carbon.const_get(type)
244
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
245
+ end
246
+ end
247
+
248
+ # Returns the string representation of the object
249
+ # @return [String] String presentation of the object
250
+ def to_s
251
+ to_hash.to_s
252
+ end
253
+
254
+ # to_body is an alias to to_hash (backward compatibility)
255
+ # @return [Hash] Returns the object in the form of hash
256
+ def to_body
257
+ to_hash
258
+ end
259
+
260
+ # Returns the object in the form of hash
261
+ # @return [Hash] Returns the object in the form of hash
262
+ def to_hash
263
+ hash = {}
264
+ self.class.attribute_map.each_pair do |attr, param|
265
+ value = self.send(attr)
266
+ if value.nil?
267
+ is_nullable = self.class.openapi_nullable.include?(attr)
268
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
269
+ end
270
+
271
+ hash[param] = _to_hash(value)
272
+ end
273
+ hash
274
+ end
275
+
276
+ # Outputs non-array value in the form of hash
277
+ # For object, use to_hash. Otherwise, just return the value
278
+ # @param [Object] value Any valid value
279
+ # @return [Hash] Returns the value in the form of hash
280
+ def _to_hash(value)
281
+ if value.is_a?(Array)
282
+ value.compact.map { |v| _to_hash(v) }
283
+ elsif value.is_a?(Hash)
284
+ {}.tap do |hash|
285
+ value.each { |k, v| hash[k] = _to_hash(v) }
286
+ end
287
+ elsif value.respond_to? :to_hash
288
+ value.to_hash
289
+ else
290
+ value
291
+ end
292
+ end
293
+
294
+ end
295
+
296
+ end
@@ -0,0 +1,262 @@
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 ServiceNowCredentials
14
+ attr_accessor :instance_subdomain
15
+
16
+ attr_accessor :client_id
17
+
18
+ attr_accessor :client_secret
19
+
20
+ attr_accessor :redirect_uri
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'instance_subdomain' => :'instance_subdomain',
26
+ :'client_id' => :'client_id',
27
+ :'client_secret' => :'client_secret',
28
+ :'redirect_uri' => :'redirect_uri'
29
+ }
30
+ end
31
+
32
+ # Returns all the JSON keys this model knows about
33
+ def self.acceptable_attributes
34
+ attribute_map.values
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'instance_subdomain' => :'String',
41
+ :'client_id' => :'String',
42
+ :'client_secret' => :'String',
43
+ :'redirect_uri' => :'String'
44
+ }
45
+ end
46
+
47
+ # List of attributes with nullable: true
48
+ def self.openapi_nullable
49
+ Set.new([
50
+ ])
51
+ end
52
+
53
+ # Initializes the object
54
+ # @param [Hash] attributes Model attributes in the form of hash
55
+ def initialize(attributes = {})
56
+ if (!attributes.is_a?(Hash))
57
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::ServiceNowCredentials` initialize method"
58
+ end
59
+
60
+ # check to see if the attribute exists and convert string to symbol for hash key
61
+ attributes = attributes.each_with_object({}) { |(k, v), h|
62
+ if (!self.class.attribute_map.key?(k.to_sym))
63
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::ServiceNowCredentials`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
64
+ end
65
+ h[k.to_sym] = v
66
+ }
67
+
68
+ if attributes.key?(:'instance_subdomain')
69
+ self.instance_subdomain = attributes[:'instance_subdomain']
70
+ end
71
+
72
+ if attributes.key?(:'client_id')
73
+ self.client_id = attributes[:'client_id']
74
+ end
75
+
76
+ if attributes.key?(:'client_secret')
77
+ self.client_secret = attributes[:'client_secret']
78
+ end
79
+
80
+ if attributes.key?(:'redirect_uri')
81
+ self.redirect_uri = attributes[:'redirect_uri']
82
+ end
83
+ end
84
+
85
+ # Show invalid properties with the reasons. Usually used together with valid?
86
+ # @return Array for valid properties with the reasons
87
+ def list_invalid_properties
88
+ invalid_properties = Array.new
89
+ if @instance_subdomain.nil?
90
+ invalid_properties.push('invalid value for "instance_subdomain", instance_subdomain cannot be nil.')
91
+ end
92
+
93
+ if @client_id.nil?
94
+ invalid_properties.push('invalid value for "client_id", client_id cannot be nil.')
95
+ end
96
+
97
+ if @client_secret.nil?
98
+ invalid_properties.push('invalid value for "client_secret", client_secret cannot be nil.')
99
+ end
100
+
101
+ if @redirect_uri.nil?
102
+ invalid_properties.push('invalid value for "redirect_uri", redirect_uri cannot be nil.')
103
+ end
104
+
105
+ invalid_properties
106
+ end
107
+
108
+ # Check to see if the all the properties in the model are valid
109
+ # @return true if the model is valid
110
+ def valid?
111
+ return false if @instance_subdomain.nil?
112
+ return false if @client_id.nil?
113
+ return false if @client_secret.nil?
114
+ return false if @redirect_uri.nil?
115
+ true
116
+ end
117
+
118
+ # Checks equality by comparing each attribute.
119
+ # @param [Object] Object to be compared
120
+ def ==(o)
121
+ return true if self.equal?(o)
122
+ self.class == o.class &&
123
+ instance_subdomain == o.instance_subdomain &&
124
+ client_id == o.client_id &&
125
+ client_secret == o.client_secret &&
126
+ redirect_uri == o.redirect_uri
127
+ end
128
+
129
+ # @see the `==` method
130
+ # @param [Object] Object to be compared
131
+ def eql?(o)
132
+ self == o
133
+ end
134
+
135
+ # Calculates hash code according to all attributes.
136
+ # @return [Integer] Hash code
137
+ def hash
138
+ [instance_subdomain, client_id, client_secret, redirect_uri].hash
139
+ end
140
+
141
+ # Builds the object from hash
142
+ # @param [Hash] attributes Model attributes in the form of hash
143
+ # @return [Object] Returns the model itself
144
+ def self.build_from_hash(attributes)
145
+ new.build_from_hash(attributes)
146
+ end
147
+
148
+ # Builds the object from hash
149
+ # @param [Hash] attributes Model attributes in the form of hash
150
+ # @return [Object] Returns the model itself
151
+ def build_from_hash(attributes)
152
+ return nil unless attributes.is_a?(Hash)
153
+ attributes = attributes.transform_keys(&:to_sym)
154
+ self.class.openapi_types.each_pair do |key, type|
155
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
156
+ self.send("#{key}=", nil)
157
+ elsif type =~ /\AArray<(.*)>/i
158
+ # check to ensure the input is an array given that the attribute
159
+ # is documented as an array but the input is not
160
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
161
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
162
+ end
163
+ elsif !attributes[self.class.attribute_map[key]].nil?
164
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
165
+ end
166
+ end
167
+
168
+ self
169
+ end
170
+
171
+ # Deserializes the data based on type
172
+ # @param string type Data type
173
+ # @param string value Value to be deserialized
174
+ # @return [Object] Deserialized data
175
+ def _deserialize(type, value)
176
+ case type.to_sym
177
+ when :Time
178
+ Time.parse(value)
179
+ when :Date
180
+ Date.parse(value)
181
+ when :String
182
+ value.to_s
183
+ when :Integer
184
+ value.to_i
185
+ when :Float
186
+ value.to_f
187
+ when :Boolean
188
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
189
+ true
190
+ else
191
+ false
192
+ end
193
+ when :Object
194
+ # generic object (usually a Hash), return directly
195
+ value
196
+ when /\AArray<(?<inner_type>.+)>\z/
197
+ inner_type = Regexp.last_match[:inner_type]
198
+ value.map { |v| _deserialize(inner_type, v) }
199
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
200
+ k_type = Regexp.last_match[:k_type]
201
+ v_type = Regexp.last_match[:v_type]
202
+ {}.tap do |hash|
203
+ value.each do |k, v|
204
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
205
+ end
206
+ end
207
+ else # model
208
+ # models (e.g. Pet) or oneOf
209
+ klass = Carbon.const_get(type)
210
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
211
+ end
212
+ end
213
+
214
+ # Returns the string representation of the object
215
+ # @return [String] String presentation of the object
216
+ def to_s
217
+ to_hash.to_s
218
+ end
219
+
220
+ # to_body is an alias to to_hash (backward compatibility)
221
+ # @return [Hash] Returns the object in the form of hash
222
+ def to_body
223
+ to_hash
224
+ end
225
+
226
+ # Returns the object in the form of hash
227
+ # @return [Hash] Returns the object in the form of hash
228
+ def to_hash
229
+ hash = {}
230
+ self.class.attribute_map.each_pair do |attr, param|
231
+ value = self.send(attr)
232
+ if value.nil?
233
+ is_nullable = self.class.openapi_nullable.include?(attr)
234
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
235
+ end
236
+
237
+ hash[param] = _to_hash(value)
238
+ end
239
+ hash
240
+ end
241
+
242
+ # Outputs non-array value in the form of hash
243
+ # For object, use to_hash. Otherwise, just return the value
244
+ # @param [Object] value Any valid value
245
+ # @return [Hash] Returns the value in the form of hash
246
+ def _to_hash(value)
247
+ if value.is_a?(Array)
248
+ value.compact.map { |v| _to_hash(v) }
249
+ elsif value.is_a?(Hash)
250
+ {}.tap do |hash|
251
+ value.each { |k, v| hash[k] = _to_hash(v) }
252
+ end
253
+ elsif value.respond_to? :to_hash
254
+ value.to_hash
255
+ else
256
+ value
257
+ end
258
+ end
259
+
260
+ end
261
+
262
+ end