carbon_ruby_sdk 0.2.41 → 0.2.43

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +273 -3
  4. data/lib/carbon_ruby_sdk/api/data_sources_api.rb +196 -0
  5. data/lib/carbon_ruby_sdk/api/files_api.rb +4 -4
  6. data/lib/carbon_ruby_sdk/api/integrations_api.rb +48 -16
  7. data/lib/carbon_ruby_sdk/api/users_api.rb +71 -0
  8. data/lib/carbon_ruby_sdk/api/white_label_api.rb +393 -0
  9. data/lib/carbon_ruby_sdk/models/add_data_source_tags_input.rb +234 -0
  10. data/lib/carbon_ruby_sdk/models/azure_blob_auth_request.rb +14 -4
  11. data/lib/carbon_ruby_sdk/models/cold_storage_props.rb +1 -1
  12. data/lib/carbon_ruby_sdk/models/credentials.rb +244 -0
  13. data/lib/carbon_ruby_sdk/models/delete_white_label_request.rb +222 -0
  14. data/lib/carbon_ruby_sdk/models/external_source_item.rb +11 -1
  15. data/lib/carbon_ruby_sdk/models/fresh_desk_connect_request.rb +15 -5
  16. data/lib/carbon_ruby_sdk/models/gitbook_connect_request.rb +15 -5
  17. data/lib/carbon_ruby_sdk/models/github_connect_request.rb +14 -4
  18. data/lib/carbon_ruby_sdk/models/google_drive_credentials.rb +254 -0
  19. data/lib/carbon_ruby_sdk/models/google_drive_white_label_input.rb +230 -0
  20. data/lib/carbon_ruby_sdk/models/guru_connect_request.rb +15 -5
  21. data/lib/carbon_ruby_sdk/models/list_white_label_request.rb +246 -0
  22. data/lib/carbon_ruby_sdk/models/o_auth_url_request.rb +15 -5
  23. data/lib/carbon_ruby_sdk/models/one_drive_sharepoint_credentials.rb +264 -0
  24. data/lib/carbon_ruby_sdk/models/one_drive_sharepoint_white_label_input.rb +234 -0
  25. data/lib/carbon_ruby_sdk/models/one_drive_sharepoint_white_label_input_data_source_type.rb +36 -0
  26. data/lib/carbon_ruby_sdk/models/organization_user_data_source_api.rb +15 -1
  27. data/lib/carbon_ruby_sdk/models/organization_user_data_source_filters.rb +12 -1
  28. data/lib/carbon_ruby_sdk/models/remove_data_source_tags_input.rb +242 -0
  29. data/lib/carbon_ruby_sdk/models/rss_feed_input.rb +15 -5
  30. data/lib/carbon_ruby_sdk/models/s3_auth_request.rb +15 -5
  31. data/lib/carbon_ruby_sdk/models/sync_options.rb +15 -5
  32. data/lib/carbon_ruby_sdk/models/user_response.rb +18 -4
  33. data/lib/carbon_ruby_sdk/models/white_label_create_request_inner.rb +255 -0
  34. data/lib/carbon_ruby_sdk/models/white_label_filters.rb +230 -0
  35. data/lib/carbon_ruby_sdk/models/white_label_input.rb +234 -0
  36. data/lib/carbon_ruby_sdk/models/white_label_input_data_source_type.rb +48 -0
  37. data/lib/carbon_ruby_sdk/models/white_label_order_by_columns.rb +36 -0
  38. data/lib/carbon_ruby_sdk/models/white_label_update_request.rb +255 -0
  39. data/lib/carbon_ruby_sdk/models/white_labeling_response.rb +18 -4
  40. data/lib/carbon_ruby_sdk/version.rb +1 -1
  41. data/lib/carbon_ruby_sdk.rb +19 -0
  42. data/spec/api/data_sources_api_spec.rb +22 -0
  43. data/spec/api/files_api_spec.rb +1 -1
  44. data/spec/api/users_api_spec.rb +10 -0
  45. data/spec/api/white_label_api_spec.rb +73 -0
  46. data/spec/models/add_data_source_tags_input_spec.rb +34 -0
  47. data/spec/models/azure_blob_auth_request_spec.rb +6 -0
  48. data/spec/models/credentials_spec.rb +40 -0
  49. data/spec/models/delete_white_label_request_spec.rb +28 -0
  50. data/spec/models/external_source_item_spec.rb +6 -0
  51. data/spec/models/fresh_desk_connect_request_spec.rb +6 -0
  52. data/spec/models/gitbook_connect_request_spec.rb +6 -0
  53. data/spec/models/github_connect_request_spec.rb +6 -0
  54. data/spec/models/google_drive_credentials_spec.rb +46 -0
  55. data/spec/models/google_drive_white_label_input_spec.rb +34 -0
  56. data/spec/models/guru_connect_request_spec.rb +6 -0
  57. data/spec/models/list_white_label_request_spec.rb +46 -0
  58. data/spec/models/o_auth_url_request_spec.rb +6 -0
  59. data/spec/models/one_drive_sharepoint_credentials_spec.rb +52 -0
  60. data/spec/models/one_drive_sharepoint_white_label_input_data_source_type_spec.rb +22 -0
  61. data/spec/models/one_drive_sharepoint_white_label_input_spec.rb +34 -0
  62. data/spec/models/organization_user_data_source_api_spec.rb +6 -0
  63. data/spec/models/organization_user_data_source_filters_spec.rb +6 -0
  64. data/spec/models/remove_data_source_tags_input_spec.rb +40 -0
  65. data/spec/models/rss_feed_input_spec.rb +6 -0
  66. data/spec/models/s3_auth_request_spec.rb +6 -0
  67. data/spec/models/sync_options_spec.rb +6 -0
  68. data/spec/models/user_response_spec.rb +6 -0
  69. data/spec/models/white_label_create_request_inner_spec.rb +34 -0
  70. data/spec/models/white_label_filters_spec.rb +34 -0
  71. data/spec/models/white_label_input_data_source_type_spec.rb +22 -0
  72. data/spec/models/white_label_input_spec.rb +34 -0
  73. data/spec/models/white_label_order_by_columns_spec.rb +22 -0
  74. data/spec/models/white_label_update_request_spec.rb +34 -0
  75. data/spec/models/white_labeling_response_spec.rb +6 -0
  76. metadata +53 -2
@@ -0,0 +1,246 @@
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 ListWhiteLabelRequest
14
+ attr_accessor :pagination
15
+
16
+ attr_accessor :order_by
17
+
18
+ attr_accessor :order_dir
19
+
20
+ attr_accessor :filters
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'pagination' => :'pagination',
26
+ :'order_by' => :'order_by',
27
+ :'order_dir' => :'order_dir',
28
+ :'filters' => :'filters'
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
+ :'pagination' => :'Pagination',
41
+ :'order_by' => :'WhiteLabelOrderByColumns',
42
+ :'order_dir' => :'OrderDir',
43
+ :'filters' => :'WhiteLabelFilters'
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::ListWhiteLabelRequest` 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::ListWhiteLabelRequest`. 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?(:'pagination')
69
+ self.pagination = attributes[:'pagination']
70
+ end
71
+
72
+ if attributes.key?(:'order_by')
73
+ self.order_by = attributes[:'order_by']
74
+ else
75
+ self.order_by = 'created_at'
76
+ end
77
+
78
+ if attributes.key?(:'order_dir')
79
+ self.order_dir = attributes[:'order_dir']
80
+ else
81
+ self.order_dir = 'asc'
82
+ end
83
+
84
+ if attributes.key?(:'filters')
85
+ self.filters = attributes[:'filters']
86
+ end
87
+ end
88
+
89
+ # Show invalid properties with the reasons. Usually used together with valid?
90
+ # @return Array for valid properties with the reasons
91
+ def list_invalid_properties
92
+ invalid_properties = Array.new
93
+ invalid_properties
94
+ end
95
+
96
+ # Check to see if the all the properties in the model are valid
97
+ # @return true if the model is valid
98
+ def valid?
99
+ true
100
+ end
101
+
102
+ # Checks equality by comparing each attribute.
103
+ # @param [Object] Object to be compared
104
+ def ==(o)
105
+ return true if self.equal?(o)
106
+ self.class == o.class &&
107
+ pagination == o.pagination &&
108
+ order_by == o.order_by &&
109
+ order_dir == o.order_dir &&
110
+ filters == o.filters
111
+ end
112
+
113
+ # @see the `==` method
114
+ # @param [Object] Object to be compared
115
+ def eql?(o)
116
+ self == o
117
+ end
118
+
119
+ # Calculates hash code according to all attributes.
120
+ # @return [Integer] Hash code
121
+ def hash
122
+ [pagination, order_by, order_dir, filters].hash
123
+ end
124
+
125
+ # Builds the object from hash
126
+ # @param [Hash] attributes Model attributes in the form of hash
127
+ # @return [Object] Returns the model itself
128
+ def self.build_from_hash(attributes)
129
+ new.build_from_hash(attributes)
130
+ end
131
+
132
+ # Builds the object from hash
133
+ # @param [Hash] attributes Model attributes in the form of hash
134
+ # @return [Object] Returns the model itself
135
+ def build_from_hash(attributes)
136
+ return nil unless attributes.is_a?(Hash)
137
+ attributes = attributes.transform_keys(&:to_sym)
138
+ self.class.openapi_types.each_pair do |key, type|
139
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
140
+ self.send("#{key}=", nil)
141
+ elsif type =~ /\AArray<(.*)>/i
142
+ # check to ensure the input is an array given that the attribute
143
+ # is documented as an array but the input is not
144
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
145
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
146
+ end
147
+ elsif !attributes[self.class.attribute_map[key]].nil?
148
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
149
+ end
150
+ end
151
+
152
+ self
153
+ end
154
+
155
+ # Deserializes the data based on type
156
+ # @param string type Data type
157
+ # @param string value Value to be deserialized
158
+ # @return [Object] Deserialized data
159
+ def _deserialize(type, value)
160
+ case type.to_sym
161
+ when :Time
162
+ Time.parse(value)
163
+ when :Date
164
+ Date.parse(value)
165
+ when :String
166
+ value.to_s
167
+ when :Integer
168
+ value.to_i
169
+ when :Float
170
+ value.to_f
171
+ when :Boolean
172
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
173
+ true
174
+ else
175
+ false
176
+ end
177
+ when :Object
178
+ # generic object (usually a Hash), return directly
179
+ value
180
+ when /\AArray<(?<inner_type>.+)>\z/
181
+ inner_type = Regexp.last_match[:inner_type]
182
+ value.map { |v| _deserialize(inner_type, v) }
183
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
184
+ k_type = Regexp.last_match[:k_type]
185
+ v_type = Regexp.last_match[:v_type]
186
+ {}.tap do |hash|
187
+ value.each do |k, v|
188
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
189
+ end
190
+ end
191
+ else # model
192
+ # models (e.g. Pet) or oneOf
193
+ klass = Carbon.const_get(type)
194
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
195
+ end
196
+ end
197
+
198
+ # Returns the string representation of the object
199
+ # @return [String] String presentation of the object
200
+ def to_s
201
+ to_hash.to_s
202
+ end
203
+
204
+ # to_body is an alias to to_hash (backward compatibility)
205
+ # @return [Hash] Returns the object in the form of hash
206
+ def to_body
207
+ to_hash
208
+ end
209
+
210
+ # Returns the object in the form of hash
211
+ # @return [Hash] Returns the object in the form of hash
212
+ def to_hash
213
+ hash = {}
214
+ self.class.attribute_map.each_pair do |attr, param|
215
+ value = self.send(attr)
216
+ if value.nil?
217
+ is_nullable = self.class.openapi_nullable.include?(attr)
218
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
219
+ end
220
+
221
+ hash[param] = _to_hash(value)
222
+ end
223
+ hash
224
+ end
225
+
226
+ # Outputs non-array value in the form of hash
227
+ # For object, use to_hash. Otherwise, just return the value
228
+ # @param [Object] value Any valid value
229
+ # @return [Hash] Returns the value in the form of hash
230
+ def _to_hash(value)
231
+ if value.is_a?(Array)
232
+ value.compact.map { |v| _to_hash(v) }
233
+ elsif value.is_a?(Hash)
234
+ {}.tap do |hash|
235
+ value.each { |k, v| hash[k] = _to_hash(v) }
236
+ end
237
+ elsif value.respond_to? :to_hash
238
+ value.to_hash
239
+ else
240
+ value
241
+ end
242
+ end
243
+
244
+ end
245
+
246
+ end
@@ -80,6 +80,9 @@ module Carbon
80
80
 
81
81
  attr_accessor :servicenow_credentials
82
82
 
83
+ # Tags to be associated with the data source. If the data source already has tags set, then an upsert will be performed.
84
+ attr_accessor :data_source_tags
85
+
83
86
  # Attribute mapping from ruby-style variable name to JSON key.
84
87
  def self.attribute_map
85
88
  {
@@ -111,7 +114,8 @@ module Carbon
111
114
  :'file_sync_config' => :'file_sync_config',
112
115
  :'automatically_open_file_picker' => :'automatically_open_file_picker',
113
116
  :'gong_account_email' => :'gong_account_email',
114
- :'servicenow_credentials' => :'servicenow_credentials'
117
+ :'servicenow_credentials' => :'servicenow_credentials',
118
+ :'data_source_tags' => :'data_source_tags'
115
119
  }
116
120
  end
117
121
 
@@ -151,7 +155,8 @@ module Carbon
151
155
  :'file_sync_config' => :'FileSyncConfigNullable',
152
156
  :'automatically_open_file_picker' => :'Boolean',
153
157
  :'gong_account_email' => :'String',
154
- :'servicenow_credentials' => :'ServiceNowCredentialsNullable'
158
+ :'servicenow_credentials' => :'ServiceNowCredentialsNullable',
159
+ :'data_source_tags' => :'Object'
155
160
  }
156
161
  end
157
162
 
@@ -181,7 +186,7 @@ module Carbon
181
186
  :'file_sync_config',
182
187
  :'automatically_open_file_picker',
183
188
  :'gong_account_email',
184
- :'servicenow_credentials'
189
+ :'servicenow_credentials',
185
190
  ])
186
191
  end
187
192
 
@@ -343,6 +348,10 @@ module Carbon
343
348
  if attributes.key?(:'servicenow_credentials')
344
349
  self.servicenow_credentials = attributes[:'servicenow_credentials']
345
350
  end
351
+
352
+ if attributes.key?(:'data_source_tags')
353
+ self.data_source_tags = attributes[:'data_source_tags']
354
+ end
346
355
  end
347
356
 
348
357
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -396,7 +405,8 @@ module Carbon
396
405
  file_sync_config == o.file_sync_config &&
397
406
  automatically_open_file_picker == o.automatically_open_file_picker &&
398
407
  gong_account_email == o.gong_account_email &&
399
- servicenow_credentials == o.servicenow_credentials
408
+ servicenow_credentials == o.servicenow_credentials &&
409
+ data_source_tags == o.data_source_tags
400
410
  end
401
411
 
402
412
  # @see the `==` method
@@ -408,7 +418,7 @@ module Carbon
408
418
  # Calculates hash code according to all attributes.
409
419
  # @return [Integer] Hash code
410
420
  def hash
411
- [tags, scope, service, chunk_size, chunk_overlap, skip_embedding_generation, embedding_model, zendesk_subdomain, microsoft_tenant, sharepoint_site_name, confluence_subdomain, generate_sparse_vectors, prepend_filename_to_chunks, max_items_per_chunk, salesforce_domain, sync_files_on_connection, set_page_as_boundary, data_source_id, connecting_new_account, request_id, use_ocr, parse_pdf_tables_with_ocr, enable_file_picker, sync_source_items, incremental_sync, file_sync_config, automatically_open_file_picker, gong_account_email, servicenow_credentials].hash
421
+ [tags, scope, service, chunk_size, chunk_overlap, skip_embedding_generation, embedding_model, zendesk_subdomain, microsoft_tenant, sharepoint_site_name, confluence_subdomain, generate_sparse_vectors, prepend_filename_to_chunks, max_items_per_chunk, salesforce_domain, sync_files_on_connection, set_page_as_boundary, data_source_id, connecting_new_account, request_id, use_ocr, parse_pdf_tables_with_ocr, enable_file_picker, sync_source_items, incremental_sync, file_sync_config, automatically_open_file_picker, gong_account_email, servicenow_credentials, data_source_tags].hash
412
422
  end
413
423
 
414
424
  # Builds the object from hash
@@ -0,0 +1,264 @@
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 OneDriveSharepointCredentials
14
+ attr_accessor :client_id
15
+
16
+ attr_accessor :redirect_uri
17
+
18
+ attr_accessor :client_secret
19
+
20
+ attr_accessor :file_picker_client_id
21
+
22
+ attr_accessor :file_picker_redirect_uri
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'client_id' => :'client_id',
28
+ :'redirect_uri' => :'redirect_uri',
29
+ :'client_secret' => :'client_secret',
30
+ :'file_picker_client_id' => :'file_picker_client_id',
31
+ :'file_picker_redirect_uri' => :'file_picker_redirect_uri'
32
+ }
33
+ end
34
+
35
+ # Returns all the JSON keys this model knows about
36
+ def self.acceptable_attributes
37
+ attribute_map.values
38
+ end
39
+
40
+ # Attribute type mapping.
41
+ def self.openapi_types
42
+ {
43
+ :'client_id' => :'String',
44
+ :'redirect_uri' => :'String',
45
+ :'client_secret' => :'String',
46
+ :'file_picker_client_id' => :'String',
47
+ :'file_picker_redirect_uri' => :'String'
48
+ }
49
+ end
50
+
51
+ # List of attributes with nullable: true
52
+ def self.openapi_nullable
53
+ Set.new([
54
+ :'client_secret',
55
+ :'file_picker_client_id',
56
+ :'file_picker_redirect_uri'
57
+ ])
58
+ end
59
+
60
+ # Initializes the object
61
+ # @param [Hash] attributes Model attributes in the form of hash
62
+ def initialize(attributes = {})
63
+ if (!attributes.is_a?(Hash))
64
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Carbon::OneDriveSharepointCredentials` initialize method"
65
+ end
66
+
67
+ # check to see if the attribute exists and convert string to symbol for hash key
68
+ attributes = attributes.each_with_object({}) { |(k, v), h|
69
+ if (!self.class.attribute_map.key?(k.to_sym))
70
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Carbon::OneDriveSharepointCredentials`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
71
+ end
72
+ h[k.to_sym] = v
73
+ }
74
+
75
+ if attributes.key?(:'client_id')
76
+ self.client_id = attributes[:'client_id']
77
+ end
78
+
79
+ if attributes.key?(:'redirect_uri')
80
+ self.redirect_uri = attributes[:'redirect_uri']
81
+ end
82
+
83
+ if attributes.key?(:'client_secret')
84
+ self.client_secret = attributes[:'client_secret']
85
+ end
86
+
87
+ if attributes.key?(:'file_picker_client_id')
88
+ self.file_picker_client_id = attributes[:'file_picker_client_id']
89
+ end
90
+
91
+ if attributes.key?(:'file_picker_redirect_uri')
92
+ self.file_picker_redirect_uri = attributes[:'file_picker_redirect_uri']
93
+ end
94
+ end
95
+
96
+ # Show invalid properties with the reasons. Usually used together with valid?
97
+ # @return Array for valid properties with the reasons
98
+ def list_invalid_properties
99
+ invalid_properties = Array.new
100
+ if @client_id.nil?
101
+ invalid_properties.push('invalid value for "client_id", client_id cannot be nil.')
102
+ end
103
+
104
+ if @redirect_uri.nil?
105
+ invalid_properties.push('invalid value for "redirect_uri", redirect_uri cannot be nil.')
106
+ end
107
+
108
+ invalid_properties
109
+ end
110
+
111
+ # Check to see if the all the properties in the model are valid
112
+ # @return true if the model is valid
113
+ def valid?
114
+ return false if @client_id.nil?
115
+ return false if @redirect_uri.nil?
116
+ true
117
+ end
118
+
119
+ # Checks equality by comparing each attribute.
120
+ # @param [Object] Object to be compared
121
+ def ==(o)
122
+ return true if self.equal?(o)
123
+ self.class == o.class &&
124
+ client_id == o.client_id &&
125
+ redirect_uri == o.redirect_uri &&
126
+ client_secret == o.client_secret &&
127
+ file_picker_client_id == o.file_picker_client_id &&
128
+ file_picker_redirect_uri == o.file_picker_redirect_uri
129
+ end
130
+
131
+ # @see the `==` method
132
+ # @param [Object] Object to be compared
133
+ def eql?(o)
134
+ self == o
135
+ end
136
+
137
+ # Calculates hash code according to all attributes.
138
+ # @return [Integer] Hash code
139
+ def hash
140
+ [client_id, redirect_uri, client_secret, file_picker_client_id, file_picker_redirect_uri].hash
141
+ end
142
+
143
+ # Builds the object from hash
144
+ # @param [Hash] attributes Model attributes in the form of hash
145
+ # @return [Object] Returns the model itself
146
+ def self.build_from_hash(attributes)
147
+ new.build_from_hash(attributes)
148
+ end
149
+
150
+ # Builds the object from hash
151
+ # @param [Hash] attributes Model attributes in the form of hash
152
+ # @return [Object] Returns the model itself
153
+ def build_from_hash(attributes)
154
+ return nil unless attributes.is_a?(Hash)
155
+ attributes = attributes.transform_keys(&:to_sym)
156
+ self.class.openapi_types.each_pair do |key, type|
157
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
158
+ self.send("#{key}=", nil)
159
+ elsif type =~ /\AArray<(.*)>/i
160
+ # check to ensure the input is an array given that the attribute
161
+ # is documented as an array but the input is not
162
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
163
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
164
+ end
165
+ elsif !attributes[self.class.attribute_map[key]].nil?
166
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
167
+ end
168
+ end
169
+
170
+ self
171
+ end
172
+
173
+ # Deserializes the data based on type
174
+ # @param string type Data type
175
+ # @param string value Value to be deserialized
176
+ # @return [Object] Deserialized data
177
+ def _deserialize(type, value)
178
+ case type.to_sym
179
+ when :Time
180
+ Time.parse(value)
181
+ when :Date
182
+ Date.parse(value)
183
+ when :String
184
+ value.to_s
185
+ when :Integer
186
+ value.to_i
187
+ when :Float
188
+ value.to_f
189
+ when :Boolean
190
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
191
+ true
192
+ else
193
+ false
194
+ end
195
+ when :Object
196
+ # generic object (usually a Hash), return directly
197
+ value
198
+ when /\AArray<(?<inner_type>.+)>\z/
199
+ inner_type = Regexp.last_match[:inner_type]
200
+ value.map { |v| _deserialize(inner_type, v) }
201
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
202
+ k_type = Regexp.last_match[:k_type]
203
+ v_type = Regexp.last_match[:v_type]
204
+ {}.tap do |hash|
205
+ value.each do |k, v|
206
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
207
+ end
208
+ end
209
+ else # model
210
+ # models (e.g. Pet) or oneOf
211
+ klass = Carbon.const_get(type)
212
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
213
+ end
214
+ end
215
+
216
+ # Returns the string representation of the object
217
+ # @return [String] String presentation of the object
218
+ def to_s
219
+ to_hash.to_s
220
+ end
221
+
222
+ # to_body is an alias to to_hash (backward compatibility)
223
+ # @return [Hash] Returns the object in the form of hash
224
+ def to_body
225
+ to_hash
226
+ end
227
+
228
+ # Returns the object in the form of hash
229
+ # @return [Hash] Returns the object in the form of hash
230
+ def to_hash
231
+ hash = {}
232
+ self.class.attribute_map.each_pair do |attr, param|
233
+ value = self.send(attr)
234
+ if value.nil?
235
+ is_nullable = self.class.openapi_nullable.include?(attr)
236
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
237
+ end
238
+
239
+ hash[param] = _to_hash(value)
240
+ end
241
+ hash
242
+ end
243
+
244
+ # Outputs non-array value in the form of hash
245
+ # For object, use to_hash. Otherwise, just return the value
246
+ # @param [Object] value Any valid value
247
+ # @return [Hash] Returns the value in the form of hash
248
+ def _to_hash(value)
249
+ if value.is_a?(Array)
250
+ value.compact.map { |v| _to_hash(v) }
251
+ elsif value.is_a?(Hash)
252
+ {}.tap do |hash|
253
+ value.each { |k, v| hash[k] = _to_hash(v) }
254
+ end
255
+ elsif value.respond_to? :to_hash
256
+ value.to_hash
257
+ else
258
+ value
259
+ end
260
+ end
261
+
262
+ end
263
+
264
+ end