carbon_ruby_sdk 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +57 -3
  4. data/lib/carbon_ruby_sdk/api/files_api.rb +6 -6
  5. data/lib/carbon_ruby_sdk/api/integrations_api.rb +104 -8
  6. data/lib/carbon_ruby_sdk/models/authentication_property.rb +436 -0
  7. data/lib/carbon_ruby_sdk/models/confluence_authentication.rb +254 -0
  8. data/lib/carbon_ruby_sdk/models/connect_data_source_input.rb +229 -0
  9. data/lib/carbon_ruby_sdk/models/connect_data_source_response.rb +230 -0
  10. data/lib/carbon_ruby_sdk/models/freskdesk_authentication.rb +244 -0
  11. data/lib/carbon_ruby_sdk/models/gitbook_authetication.rb +244 -0
  12. data/lib/carbon_ruby_sdk/models/notion_authentication.rb +244 -0
  13. data/lib/carbon_ruby_sdk/models/o_auth_authentication.rb +244 -0
  14. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +1 -0
  15. data/lib/carbon_ruby_sdk/models/organization_user_data_source_api.rb +11 -1
  16. data/lib/carbon_ruby_sdk/models/s3_authentication.rb +244 -0
  17. data/lib/carbon_ruby_sdk/models/s3_file_sync_input.rb +1 -0
  18. data/lib/carbon_ruby_sdk/models/salesforce_authentication.rb +254 -0
  19. data/lib/carbon_ruby_sdk/models/sharepoint_authentication.rb +268 -0
  20. data/lib/carbon_ruby_sdk/models/simple_o_auth_data_sources.rb +41 -0
  21. data/lib/carbon_ruby_sdk/models/sitemap_scrape_request.rb +15 -0
  22. data/lib/carbon_ruby_sdk/models/sync_files_request.rb +1 -0
  23. data/lib/carbon_ruby_sdk/models/sync_options.rb +323 -0
  24. data/lib/carbon_ruby_sdk/models/upload_file_from_url_input.rb +1 -0
  25. data/lib/carbon_ruby_sdk/models/webscrape_request.rb +30 -0
  26. data/lib/carbon_ruby_sdk/models/zendesk_authentication.rb +244 -0
  27. data/lib/carbon_ruby_sdk/models/zotero_authentication.rb +272 -0
  28. data/lib/carbon_ruby_sdk/version.rb +1 -1
  29. data/lib/carbon_ruby_sdk.rb +15 -0
  30. data/spec/api/files_api_spec.rb +1 -1
  31. data/spec/api/integrations_api_spec.rb +11 -0
  32. data/spec/models/authentication_property_spec.rb +112 -0
  33. data/spec/models/confluence_authentication_spec.rb +46 -0
  34. data/spec/models/connect_data_source_input_spec.rb +34 -0
  35. data/spec/models/connect_data_source_response_spec.rb +34 -0
  36. data/spec/models/freskdesk_authentication_spec.rb +40 -0
  37. data/spec/models/gitbook_authetication_spec.rb +40 -0
  38. data/spec/models/notion_authentication_spec.rb +40 -0
  39. data/spec/models/o_auth_authentication_spec.rb +40 -0
  40. data/spec/models/organization_user_data_source_api_spec.rb +6 -0
  41. data/spec/models/s3_authentication_spec.rb +40 -0
  42. data/spec/models/salesforce_authentication_spec.rb +46 -0
  43. data/spec/models/sharepoint_authentication_spec.rb +52 -0
  44. data/spec/models/simple_o_auth_data_sources_spec.rb +22 -0
  45. data/spec/models/sync_options_spec.rb +82 -0
  46. data/spec/models/zendesk_authentication_spec.rb +40 -0
  47. data/spec/models/zotero_authentication_spec.rb +52 -0
  48. metadata +47 -2
@@ -0,0 +1,323 @@
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 SyncOptions
14
+ attr_accessor :tags
15
+
16
+ attr_accessor :chunk_size
17
+
18
+ attr_accessor :chunk_overlap
19
+
20
+ attr_accessor :skip_embedding_generation
21
+
22
+ attr_accessor :embedding_model
23
+
24
+ attr_accessor :generate_sparse_vectors
25
+
26
+ attr_accessor :prepend_filename_to_chunks
27
+
28
+ # Number of objects per chunk. For csv, tsv, xlsx, and json files only.
29
+ attr_accessor :max_items_per_chunk
30
+
31
+ # Used to specify whether Carbon should attempt to sync all your files automatically when authorization is complete. This is only supported for a subset of connectors and will be ignored for the rest. Supported connectors: Intercom, Zendesk, Gitbook, Confluence, Salesforce, Freshdesk
32
+ attr_accessor :sync_files_on_connection
33
+
34
+ attr_accessor :set_page_as_boundary
35
+
36
+ # Attribute mapping from ruby-style variable name to JSON key.
37
+ def self.attribute_map
38
+ {
39
+ :'tags' => :'tags',
40
+ :'chunk_size' => :'chunk_size',
41
+ :'chunk_overlap' => :'chunk_overlap',
42
+ :'skip_embedding_generation' => :'skip_embedding_generation',
43
+ :'embedding_model' => :'embedding_model',
44
+ :'generate_sparse_vectors' => :'generate_sparse_vectors',
45
+ :'prepend_filename_to_chunks' => :'prepend_filename_to_chunks',
46
+ :'max_items_per_chunk' => :'max_items_per_chunk',
47
+ :'sync_files_on_connection' => :'sync_files_on_connection',
48
+ :'set_page_as_boundary' => :'set_page_as_boundary'
49
+ }
50
+ end
51
+
52
+ # Returns all the JSON keys this model knows about
53
+ def self.acceptable_attributes
54
+ attribute_map.values
55
+ end
56
+
57
+ # Attribute type mapping.
58
+ def self.openapi_types
59
+ {
60
+ :'tags' => :'Object',
61
+ :'chunk_size' => :'Integer',
62
+ :'chunk_overlap' => :'Integer',
63
+ :'skip_embedding_generation' => :'Boolean',
64
+ :'embedding_model' => :'EmbeddingGeneratorsNullable',
65
+ :'generate_sparse_vectors' => :'Boolean',
66
+ :'prepend_filename_to_chunks' => :'Boolean',
67
+ :'max_items_per_chunk' => :'Integer',
68
+ :'sync_files_on_connection' => :'Boolean',
69
+ :'set_page_as_boundary' => :'Boolean'
70
+ }
71
+ end
72
+
73
+ # List of attributes with nullable: true
74
+ def self.openapi_nullable
75
+ Set.new([
76
+ :'tags',
77
+ :'chunk_size',
78
+ :'chunk_overlap',
79
+ :'skip_embedding_generation',
80
+ :'embedding_model',
81
+ :'generate_sparse_vectors',
82
+ :'prepend_filename_to_chunks',
83
+ :'max_items_per_chunk',
84
+ :'sync_files_on_connection',
85
+ ])
86
+ end
87
+
88
+ # Initializes the object
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ def initialize(attributes = {})
91
+ if (!attributes.is_a?(Hash))
92
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::SyncOptions` initialize method"
93
+ end
94
+
95
+ # check to see if the attribute exists and convert string to symbol for hash key
96
+ attributes = attributes.each_with_object({}) { |(k, v), h|
97
+ if (!self.class.attribute_map.key?(k.to_sym))
98
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::SyncOptions`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
99
+ end
100
+ h[k.to_sym] = v
101
+ }
102
+
103
+ if attributes.key?(:'tags')
104
+ self.tags = attributes[:'tags']
105
+ end
106
+
107
+ if attributes.key?(:'chunk_size')
108
+ self.chunk_size = attributes[:'chunk_size']
109
+ else
110
+ self.chunk_size = 1500
111
+ end
112
+
113
+ if attributes.key?(:'chunk_overlap')
114
+ self.chunk_overlap = attributes[:'chunk_overlap']
115
+ else
116
+ self.chunk_overlap = 20
117
+ end
118
+
119
+ if attributes.key?(:'skip_embedding_generation')
120
+ self.skip_embedding_generation = attributes[:'skip_embedding_generation']
121
+ else
122
+ self.skip_embedding_generation = false
123
+ end
124
+
125
+ if attributes.key?(:'embedding_model')
126
+ self.embedding_model = attributes[:'embedding_model']
127
+ else
128
+ self.embedding_model = 'OPENAI'
129
+ end
130
+
131
+ if attributes.key?(:'generate_sparse_vectors')
132
+ self.generate_sparse_vectors = attributes[:'generate_sparse_vectors']
133
+ else
134
+ self.generate_sparse_vectors = false
135
+ end
136
+
137
+ if attributes.key?(:'prepend_filename_to_chunks')
138
+ self.prepend_filename_to_chunks = attributes[:'prepend_filename_to_chunks']
139
+ else
140
+ self.prepend_filename_to_chunks = false
141
+ end
142
+
143
+ if attributes.key?(:'max_items_per_chunk')
144
+ self.max_items_per_chunk = attributes[:'max_items_per_chunk']
145
+ end
146
+
147
+ if attributes.key?(:'sync_files_on_connection')
148
+ self.sync_files_on_connection = attributes[:'sync_files_on_connection']
149
+ else
150
+ self.sync_files_on_connection = true
151
+ end
152
+
153
+ if attributes.key?(:'set_page_as_boundary')
154
+ self.set_page_as_boundary = attributes[:'set_page_as_boundary']
155
+ else
156
+ self.set_page_as_boundary = false
157
+ end
158
+ end
159
+
160
+ # Show invalid properties with the reasons. Usually used together with valid?
161
+ # @return Array for valid properties with the reasons
162
+ def list_invalid_properties
163
+ invalid_properties = Array.new
164
+ invalid_properties
165
+ end
166
+
167
+ # Check to see if the all the properties in the model are valid
168
+ # @return true if the model is valid
169
+ def valid?
170
+ true
171
+ end
172
+
173
+ # Checks equality by comparing each attribute.
174
+ # @param [Object] Object to be compared
175
+ def ==(o)
176
+ return true if self.equal?(o)
177
+ self.class == o.class &&
178
+ tags == o.tags &&
179
+ chunk_size == o.chunk_size &&
180
+ chunk_overlap == o.chunk_overlap &&
181
+ skip_embedding_generation == o.skip_embedding_generation &&
182
+ embedding_model == o.embedding_model &&
183
+ generate_sparse_vectors == o.generate_sparse_vectors &&
184
+ prepend_filename_to_chunks == o.prepend_filename_to_chunks &&
185
+ max_items_per_chunk == o.max_items_per_chunk &&
186
+ sync_files_on_connection == o.sync_files_on_connection &&
187
+ set_page_as_boundary == o.set_page_as_boundary
188
+ end
189
+
190
+ # @see the `==` method
191
+ # @param [Object] Object to be compared
192
+ def eql?(o)
193
+ self == o
194
+ end
195
+
196
+ # Calculates hash code according to all attributes.
197
+ # @return [Integer] Hash code
198
+ def hash
199
+ [tags, chunk_size, chunk_overlap, skip_embedding_generation, embedding_model, generate_sparse_vectors, prepend_filename_to_chunks, max_items_per_chunk, sync_files_on_connection, set_page_as_boundary].hash
200
+ end
201
+
202
+ # Builds the object from hash
203
+ # @param [Hash] attributes Model attributes in the form of hash
204
+ # @return [Object] Returns the model itself
205
+ def self.build_from_hash(attributes)
206
+ new.build_from_hash(attributes)
207
+ end
208
+
209
+ # Builds the object from hash
210
+ # @param [Hash] attributes Model attributes in the form of hash
211
+ # @return [Object] Returns the model itself
212
+ def build_from_hash(attributes)
213
+ return nil unless attributes.is_a?(Hash)
214
+ attributes = attributes.transform_keys(&:to_sym)
215
+ self.class.openapi_types.each_pair do |key, type|
216
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
217
+ self.send("#{key}=", nil)
218
+ elsif type =~ /\AArray<(.*)>/i
219
+ # check to ensure the input is an array given that the attribute
220
+ # is documented as an array but the input is not
221
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
222
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
223
+ end
224
+ elsif !attributes[self.class.attribute_map[key]].nil?
225
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
226
+ end
227
+ end
228
+
229
+ self
230
+ end
231
+
232
+ # Deserializes the data based on type
233
+ # @param string type Data type
234
+ # @param string value Value to be deserialized
235
+ # @return [Object] Deserialized data
236
+ def _deserialize(type, value)
237
+ case type.to_sym
238
+ when :Time
239
+ Time.parse(value)
240
+ when :Date
241
+ Date.parse(value)
242
+ when :String
243
+ value.to_s
244
+ when :Integer
245
+ value.to_i
246
+ when :Float
247
+ value.to_f
248
+ when :Boolean
249
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
250
+ true
251
+ else
252
+ false
253
+ end
254
+ when :Object
255
+ # generic object (usually a Hash), return directly
256
+ value
257
+ when /\AArray<(?<inner_type>.+)>\z/
258
+ inner_type = Regexp.last_match[:inner_type]
259
+ value.map { |v| _deserialize(inner_type, v) }
260
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
261
+ k_type = Regexp.last_match[:k_type]
262
+ v_type = Regexp.last_match[:v_type]
263
+ {}.tap do |hash|
264
+ value.each do |k, v|
265
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
266
+ end
267
+ end
268
+ else # model
269
+ # models (e.g. Pet) or oneOf
270
+ klass = Carbon.const_get(type)
271
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
272
+ end
273
+ end
274
+
275
+ # Returns the string representation of the object
276
+ # @return [String] String presentation of the object
277
+ def to_s
278
+ to_hash.to_s
279
+ end
280
+
281
+ # to_body is an alias to to_hash (backward compatibility)
282
+ # @return [Hash] Returns the object in the form of hash
283
+ def to_body
284
+ to_hash
285
+ end
286
+
287
+ # Returns the object in the form of hash
288
+ # @return [Hash] Returns the object in the form of hash
289
+ def to_hash
290
+ hash = {}
291
+ self.class.attribute_map.each_pair do |attr, param|
292
+ value = self.send(attr)
293
+ if value.nil?
294
+ is_nullable = self.class.openapi_nullable.include?(attr)
295
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
296
+ end
297
+
298
+ hash[param] = _to_hash(value)
299
+ end
300
+ hash
301
+ end
302
+
303
+ # Outputs non-array value in the form of hash
304
+ # For object, use to_hash. Otherwise, just return the value
305
+ # @param [Object] value Any valid value
306
+ # @return [Hash] Returns the value in the form of hash
307
+ def _to_hash(value)
308
+ if value.is_a?(Array)
309
+ value.compact.map { |v| _to_hash(v) }
310
+ elsif value.is_a?(Hash)
311
+ {}.tap do |hash|
312
+ value.each { |k, v| hash[k] = _to_hash(v) }
313
+ end
314
+ elsif value.respond_to? :to_hash
315
+ value.to_hash
316
+ else
317
+ value
318
+ end
319
+ end
320
+
321
+ end
322
+
323
+ end
@@ -31,6 +31,7 @@ module Carbon
31
31
 
32
32
  attr_accessor :prepend_filename_to_chunks
33
33
 
34
+ # Number of objects per chunk. For csv, tsv, xlsx, and json files only.
34
35
  attr_accessor :max_items_per_chunk
35
36
 
36
37
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -208,6 +208,14 @@ module Carbon
208
208
  invalid_properties.push('invalid value for "url", url cannot be nil.')
209
209
  end
210
210
 
211
+ if !@recursion_depth.nil? && @recursion_depth < 0
212
+ invalid_properties.push('invalid value for "recursion_depth", must be greater than or equal to 0.')
213
+ end
214
+
215
+ if !@max_pages_to_scrape.nil? && @max_pages_to_scrape < 1
216
+ invalid_properties.push('invalid value for "max_pages_to_scrape", must be greater than or equal to 1.')
217
+ end
218
+
211
219
  invalid_properties
212
220
  end
213
221
 
@@ -215,9 +223,31 @@ module Carbon
215
223
  # @return true if the model is valid
216
224
  def valid?
217
225
  return false if @url.nil?
226
+ return false if !@recursion_depth.nil? && @recursion_depth < 0
227
+ return false if !@max_pages_to_scrape.nil? && @max_pages_to_scrape < 1
218
228
  true
219
229
  end
220
230
 
231
+ # Custom attribute writer method with validation
232
+ # @param [Object] recursion_depth Value to be assigned
233
+ def recursion_depth=(recursion_depth)
234
+ if !recursion_depth.nil? && recursion_depth < 0
235
+ fail ArgumentError, 'invalid value for "recursion_depth", must be greater than or equal to 0.'
236
+ end
237
+
238
+ @recursion_depth = recursion_depth
239
+ end
240
+
241
+ # Custom attribute writer method with validation
242
+ # @param [Object] max_pages_to_scrape Value to be assigned
243
+ def max_pages_to_scrape=(max_pages_to_scrape)
244
+ if !max_pages_to_scrape.nil? && max_pages_to_scrape < 1
245
+ fail ArgumentError, 'invalid value for "max_pages_to_scrape", must be greater than or equal to 1.'
246
+ end
247
+
248
+ @max_pages_to_scrape = max_pages_to_scrape
249
+ end
250
+
221
251
  # Checks equality by comparing each attribute.
222
252
  # @param [Object] Object to be compared
223
253
  def ==(o)
@@ -0,0 +1,244 @@
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 ZendeskAuthentication
14
+ attr_accessor :source
15
+
16
+ attr_accessor :access_token
17
+
18
+ attr_accessor :subdomain
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'source' => :'source',
24
+ :'access_token' => :'access_token',
25
+ :'subdomain' => :'subdomain'
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
+ :'source' => :'Object',
38
+ :'access_token' => :'String',
39
+ :'subdomain' => :'String'
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([
46
+ :'source',
47
+ ])
48
+ end
49
+
50
+ # Initializes the object
51
+ # @param [Hash] attributes Model attributes in the form of hash
52
+ def initialize(attributes = {})
53
+ if (!attributes.is_a?(Hash))
54
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::ZendeskAuthentication` initialize method"
55
+ end
56
+
57
+ # check to see if the attribute exists and convert string to symbol for hash key
58
+ attributes = attributes.each_with_object({}) { |(k, v), h|
59
+ if (!self.class.attribute_map.key?(k.to_sym))
60
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::ZendeskAuthentication`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
61
+ end
62
+ h[k.to_sym] = v
63
+ }
64
+
65
+ if attributes.key?(:'source')
66
+ self.source = attributes[:'source']
67
+ end
68
+
69
+ if attributes.key?(:'access_token')
70
+ self.access_token = attributes[:'access_token']
71
+ end
72
+
73
+ if attributes.key?(:'subdomain')
74
+ self.subdomain = attributes[:'subdomain']
75
+ end
76
+ end
77
+
78
+ # Show invalid properties with the reasons. Usually used together with valid?
79
+ # @return Array for valid properties with the reasons
80
+ def list_invalid_properties
81
+ invalid_properties = Array.new
82
+ if @access_token.nil?
83
+ invalid_properties.push('invalid value for "access_token", access_token cannot be nil.')
84
+ end
85
+
86
+ if @subdomain.nil?
87
+ invalid_properties.push('invalid value for "subdomain", subdomain cannot be nil.')
88
+ end
89
+
90
+ invalid_properties
91
+ end
92
+
93
+ # Check to see if the all the properties in the model are valid
94
+ # @return true if the model is valid
95
+ def valid?
96
+ return false if @access_token.nil?
97
+ return false if @subdomain.nil?
98
+ true
99
+ end
100
+
101
+ # Checks equality by comparing each attribute.
102
+ # @param [Object] Object to be compared
103
+ def ==(o)
104
+ return true if self.equal?(o)
105
+ self.class == o.class &&
106
+ source == o.source &&
107
+ access_token == o.access_token &&
108
+ subdomain == o.subdomain
109
+ end
110
+
111
+ # @see the `==` method
112
+ # @param [Object] Object to be compared
113
+ def eql?(o)
114
+ self == o
115
+ end
116
+
117
+ # Calculates hash code according to all attributes.
118
+ # @return [Integer] Hash code
119
+ def hash
120
+ [source, access_token, subdomain].hash
121
+ end
122
+
123
+ # Builds the object from hash
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ # @return [Object] Returns the model itself
126
+ def self.build_from_hash(attributes)
127
+ new.build_from_hash(attributes)
128
+ end
129
+
130
+ # Builds the object from hash
131
+ # @param [Hash] attributes Model attributes in the form of hash
132
+ # @return [Object] Returns the model itself
133
+ def build_from_hash(attributes)
134
+ return nil unless attributes.is_a?(Hash)
135
+ attributes = attributes.transform_keys(&:to_sym)
136
+ self.class.openapi_types.each_pair do |key, type|
137
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
138
+ self.send("#{key}=", nil)
139
+ elsif type =~ /\AArray<(.*)>/i
140
+ # check to ensure the input is an array given that the attribute
141
+ # is documented as an array but the input is not
142
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
143
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
144
+ end
145
+ elsif !attributes[self.class.attribute_map[key]].nil?
146
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
147
+ end
148
+ end
149
+
150
+ self
151
+ end
152
+
153
+ # Deserializes the data based on type
154
+ # @param string type Data type
155
+ # @param string value Value to be deserialized
156
+ # @return [Object] Deserialized data
157
+ def _deserialize(type, value)
158
+ case type.to_sym
159
+ when :Time
160
+ Time.parse(value)
161
+ when :Date
162
+ Date.parse(value)
163
+ when :String
164
+ value.to_s
165
+ when :Integer
166
+ value.to_i
167
+ when :Float
168
+ value.to_f
169
+ when :Boolean
170
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
171
+ true
172
+ else
173
+ false
174
+ end
175
+ when :Object
176
+ # generic object (usually a Hash), return directly
177
+ value
178
+ when /\AArray<(?<inner_type>.+)>\z/
179
+ inner_type = Regexp.last_match[:inner_type]
180
+ value.map { |v| _deserialize(inner_type, v) }
181
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
182
+ k_type = Regexp.last_match[:k_type]
183
+ v_type = Regexp.last_match[:v_type]
184
+ {}.tap do |hash|
185
+ value.each do |k, v|
186
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
187
+ end
188
+ end
189
+ else # model
190
+ # models (e.g. Pet) or oneOf
191
+ klass = Carbon.const_get(type)
192
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
193
+ end
194
+ end
195
+
196
+ # Returns the string representation of the object
197
+ # @return [String] String presentation of the object
198
+ def to_s
199
+ to_hash.to_s
200
+ end
201
+
202
+ # to_body is an alias to to_hash (backward compatibility)
203
+ # @return [Hash] Returns the object in the form of hash
204
+ def to_body
205
+ to_hash
206
+ end
207
+
208
+ # Returns the object in the form of hash
209
+ # @return [Hash] Returns the object in the form of hash
210
+ def to_hash
211
+ hash = {}
212
+ self.class.attribute_map.each_pair do |attr, param|
213
+ value = self.send(attr)
214
+ if value.nil?
215
+ is_nullable = self.class.openapi_nullable.include?(attr)
216
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
217
+ end
218
+
219
+ hash[param] = _to_hash(value)
220
+ end
221
+ hash
222
+ end
223
+
224
+ # Outputs non-array value in the form of hash
225
+ # For object, use to_hash. Otherwise, just return the value
226
+ # @param [Object] value Any valid value
227
+ # @return [Hash] Returns the value in the form of hash
228
+ def _to_hash(value)
229
+ if value.is_a?(Array)
230
+ value.compact.map { |v| _to_hash(v) }
231
+ elsif value.is_a?(Hash)
232
+ {}.tap do |hash|
233
+ value.each { |k, v| hash[k] = _to_hash(v) }
234
+ end
235
+ elsif value.respond_to? :to_hash
236
+ value.to_hash
237
+ else
238
+ value
239
+ end
240
+ end
241
+
242
+ end
243
+
244
+ end