algolia 3.37.0 → 3.38.0

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 (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/algolia/api/monitoring_client.rb +2 -2
  5. data/lib/algolia/models/composition/{external.rb → injected_item_external.rb} +6 -3
  6. data/lib/algolia/models/composition/{external_source.rb → injected_item_external_source.rb} +11 -4
  7. data/lib/algolia/models/composition/injected_item_recommend_source.rb +216 -0
  8. data/lib/algolia/models/composition/{search.rb → injected_item_search.rb} +6 -3
  9. data/lib/algolia/models/composition/{search_source.rb → injected_item_search_source.rb} +11 -4
  10. data/lib/algolia/models/composition/injected_item_source.rb +3 -2
  11. data/lib/algolia/models/composition/injection.rb +2 -2
  12. data/lib/algolia/models/composition/{injected_item.rb → injection_injected_item.rb} +3 -3
  13. data/lib/algolia/models/composition/{main.rb → injection_main.rb} +8 -6
  14. data/lib/algolia/models/composition/injection_main_recommend_source.rb +216 -0
  15. data/lib/algolia/models/composition/{composition_source.rb → injection_main_search_source.rb} +12 -4
  16. data/lib/algolia/models/composition/injection_main_source.rb +109 -0
  17. data/lib/algolia/models/composition/main_recommend.rb +250 -0
  18. data/lib/algolia/models/composition/{composition_source_search.rb → main_search.rb} +4 -4
  19. data/lib/algolia/models/composition/model.rb +33 -0
  20. data/lib/algolia/models/composition/recommend.rb +250 -0
  21. data/lib/algolia/models/search/auto_filtering_filter_entry.rb +108 -0
  22. data/lib/algolia/models/search/auto_filtering_result.rb +242 -0
  23. data/lib/algolia/models/search/browse_response.rb +10 -0
  24. data/lib/algolia/models/search/category_prediction.rb +218 -0
  25. data/lib/algolia/models/search/category_prediction_bin.rb +37 -0
  26. data/lib/algolia/models/search/hierarchy_path_entry.rb +227 -0
  27. data/lib/algolia/models/search/query_categorization.rb +248 -0
  28. data/lib/algolia/models/search/query_categorization_type.rb +36 -0
  29. data/lib/algolia/models/search/response_extensions.rb +207 -0
  30. data/lib/algolia/models/search/search_extensions.rb +207 -0
  31. data/lib/algolia/models/search/search_extensions_query_categorization.rb +218 -0
  32. data/lib/algolia/models/search/search_for_hits.rb +14 -4
  33. data/lib/algolia/models/search/search_response.rb +14 -4
  34. data/lib/algolia/version.rb +1 -1
  35. metadata +25 -9
@@ -0,0 +1,248 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Search
10
+ # Query Categorization prediction returned by the AI model. This field is empty when the model cannot categorize the query. See [Query Categorization](https://www.algolia.com/doc/guides/algolia-ai/query-categorization/).
11
+ class QueryCategorization
12
+ # Processed and normalized version of the original search query.
13
+ attr_accessor :normalized_query
14
+
15
+ # Number of times this normalized query was observed during the training window.
16
+ attr_accessor :count
17
+
18
+ attr_accessor :type
19
+
20
+ # List of category predictions with confidence levels.
21
+ attr_accessor :categories
22
+
23
+ attr_accessor :autofiltering
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :normalized_query => :normalizedQuery,
29
+ :count => :count,
30
+ :type => :type,
31
+ :categories => :categories,
32
+ :autofiltering => :autofiltering
33
+ }
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.types_mapping
38
+ {
39
+ :normalized_query => :"String",
40
+ :count => :"Integer",
41
+ :type => :"QueryCategorizationType",
42
+ :categories => :"Array<CategoryPrediction>",
43
+ :autofiltering => :"AutoFilteringResult"
44
+ }
45
+ end
46
+
47
+ # List of attributes with nullable: true
48
+ def self.openapi_nullable
49
+ Set.new(
50
+ []
51
+ )
52
+ end
53
+
54
+ # Initializes the object
55
+ # @param [Hash] attributes Model attributes in the form of hash
56
+ def initialize(attributes = {})
57
+ if (!attributes.is_a?(Hash))
58
+ raise(
59
+ ArgumentError,
60
+ "The input argument (attributes) must be a hash in `Algolia::QueryCategorization` initialize method"
61
+ )
62
+ end
63
+
64
+ # check to see if the attribute exists and convert string to symbol for hash key
65
+ attributes = attributes.each_with_object({}) { |(k, v), h|
66
+ if (!self.class.attribute_map.key?(k.to_sym))
67
+ raise(
68
+ ArgumentError,
69
+ "`#{k}` is not a valid attribute in `Algolia::QueryCategorization`. Please check the name to make sure it's valid. List of attributes: " +
70
+ self.class.attribute_map.keys.inspect
71
+ )
72
+ end
73
+
74
+ h[k.to_sym] = v
75
+ }
76
+
77
+ if attributes.key?(:normalized_query)
78
+ self.normalized_query = attributes[:normalized_query]
79
+ end
80
+
81
+ if attributes.key?(:count)
82
+ self.count = attributes[:count]
83
+ end
84
+
85
+ if attributes.key?(:type)
86
+ self.type = attributes[:type]
87
+ end
88
+
89
+ if attributes.key?(:categories)
90
+ if (value = attributes[:categories]).is_a?(Array)
91
+ self.categories = value
92
+ end
93
+ end
94
+
95
+ if attributes.key?(:autofiltering)
96
+ self.autofiltering = attributes[:autofiltering]
97
+ end
98
+ end
99
+
100
+ # Checks equality by comparing each attribute.
101
+ # @param [Object] Object to be compared
102
+ def ==(other)
103
+ return true if self.equal?(other)
104
+ self.class == other.class &&
105
+ normalized_query == other.normalized_query &&
106
+ count == other.count &&
107
+ type == other.type &&
108
+ categories == other.categories &&
109
+ autofiltering == other.autofiltering
110
+ end
111
+
112
+ # @see the `==` method
113
+ # @param [Object] Object to be compared
114
+ def eql?(other)
115
+ self == other
116
+ end
117
+
118
+ # Calculates hash code according to all attributes.
119
+ # @return [Integer] Hash code
120
+ def hash
121
+ [normalized_query, count, type, categories, autofiltering].hash
122
+ end
123
+
124
+ # Builds the object from hash
125
+ # @param [Hash] attributes Model attributes in the form of hash
126
+ # @return [Object] Returns the model itself
127
+ def self.build_from_hash(attributes)
128
+ return nil unless attributes.is_a?(Hash)
129
+ attributes = attributes.transform_keys(&:to_sym)
130
+ transformed_hash = {}
131
+ types_mapping.each_pair do |key, type|
132
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
133
+ transformed_hash[key.to_sym] = nil
134
+ elsif type =~ /\AArray<(.*)>/i
135
+ # check to ensure the input is an array given that the attribute
136
+ # is documented as an array but the input is not
137
+ if attributes[attribute_map[key]].is_a?(Array)
138
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
139
+ _deserialize(::Regexp.last_match(1), v)
140
+ }
141
+ end
142
+ elsif !attributes[attribute_map[key]].nil?
143
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
144
+ end
145
+ end
146
+
147
+ new(transformed_hash)
148
+ end
149
+
150
+ # Deserializes the data based on type
151
+ # @param string type Data type
152
+ # @param string value Value to be deserialized
153
+ # @return [Object] Deserialized data
154
+ def self._deserialize(type, value)
155
+ case type.to_sym
156
+ when :Time
157
+ Time.parse(value)
158
+ when :Date
159
+ Date.parse(value)
160
+ when :String
161
+ value.to_s
162
+ when :Integer
163
+ value.to_i
164
+ when :Float
165
+ value.to_f
166
+ when :Boolean
167
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
168
+ true
169
+ else
170
+ false
171
+ end
172
+
173
+ when :Object
174
+ # generic object (usually a Hash), return directly
175
+ value
176
+ when /\AArray<(?<inner_type>.+)>\z/
177
+ inner_type = Regexp.last_match[:inner_type]
178
+ value.map { |v| _deserialize(inner_type, v) }
179
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
180
+ k_type = Regexp.last_match[:k_type]
181
+ v_type = Regexp.last_match[:v_type]
182
+ {}.tap do |hash|
183
+ value.each do |k, v|
184
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
185
+ end
186
+ end
187
+ # model
188
+ else
189
+ # models (e.g. Pet) or oneOf
190
+ klass = Algolia::Search.const_get(type)
191
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
192
+ .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
+ def to_json(*_args)
209
+ to_hash.to_json
210
+ end
211
+
212
+ # Returns the object in the form of hash
213
+ # @return [Hash] Returns the object in the form of hash
214
+ def to_hash
215
+ hash = {}
216
+ self.class.attribute_map.each_pair do |attr, param|
217
+ value = send(attr)
218
+ if value.nil?
219
+ is_nullable = self.class.openapi_nullable.include?(attr)
220
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
221
+ end
222
+
223
+ hash[param] = _to_hash(value)
224
+ end
225
+
226
+ hash
227
+ end
228
+
229
+ # Outputs non-array value in the form of hash
230
+ # For object, use to_hash. Otherwise, just return the value
231
+ # @param [Object] value Any valid value
232
+ # @return [Hash] Returns the value in the form of hash
233
+ def _to_hash(value)
234
+ if value.is_a?(Array)
235
+ value.compact.map { |v| _to_hash(v) }
236
+ elsif value.is_a?(Hash)
237
+ {}.tap do |hash|
238
+ value.each { |k, v| hash[k] = _to_hash(v) }
239
+ end
240
+ elsif value.respond_to?(:to_hash)
241
+ value.to_hash
242
+ else
243
+ value
244
+ end
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Search
10
+ class QueryCategorizationType
11
+ NARROW = "narrow".freeze
12
+ BROAD = "broad".freeze
13
+ AMBIGUOUS = "ambiguous".freeze
14
+ NONE = "none".freeze
15
+
16
+ def self.all_vars
17
+ @all_vars ||= [NARROW, BROAD, AMBIGUOUS, NONE].freeze
18
+ end
19
+
20
+ # Builds the enum from string
21
+ # @param [String] The enum value in the form of the string
22
+ # @return [String] The enum value
23
+ def self.build_from_hash(value)
24
+ new.build_from_hash(value)
25
+ end
26
+
27
+ # Builds the enum from string
28
+ # @param [String] The enum value in the form of the string
29
+ # @return [String] The enum value
30
+ def build_from_hash(value)
31
+ return value if QueryCategorizationType.all_vars.include?(value)
32
+ raise "Invalid ENUM value #{value} for class #QueryCategorizationType"
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,207 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Search
10
+ # AI-generated metadata returned alongside search results. Present when Algolia AI features such as [Query Categorization](https://www.algolia.com/doc/guides/algolia-ai/query-categorization/) are enabled.
11
+ class ResponseExtensions
12
+ attr_accessor :query_categorization
13
+
14
+ # Attribute mapping from ruby-style variable name to JSON key.
15
+ def self.attribute_map
16
+ {
17
+ :query_categorization => :queryCategorization
18
+ }
19
+ end
20
+
21
+ # Attribute type mapping.
22
+ def self.types_mapping
23
+ {
24
+ :query_categorization => :"QueryCategorization"
25
+ }
26
+ end
27
+
28
+ # List of attributes with nullable: true
29
+ def self.openapi_nullable
30
+ Set.new(
31
+ []
32
+ )
33
+ end
34
+
35
+ # Initializes the object
36
+ # @param [Hash] attributes Model attributes in the form of hash
37
+ def initialize(attributes = {})
38
+ if (!attributes.is_a?(Hash))
39
+ raise(
40
+ ArgumentError,
41
+ "The input argument (attributes) must be a hash in `Algolia::ResponseExtensions` initialize method"
42
+ )
43
+ end
44
+
45
+ # check to see if the attribute exists and convert string to symbol for hash key
46
+ attributes = attributes.each_with_object({}) { |(k, v), h|
47
+ if (!self.class.attribute_map.key?(k.to_sym))
48
+ raise(
49
+ ArgumentError,
50
+ "`#{k}` is not a valid attribute in `Algolia::ResponseExtensions`. Please check the name to make sure it's valid. List of attributes: " +
51
+ self.class.attribute_map.keys.inspect
52
+ )
53
+ end
54
+
55
+ h[k.to_sym] = v
56
+ }
57
+
58
+ if attributes.key?(:query_categorization)
59
+ self.query_categorization = attributes[:query_categorization]
60
+ end
61
+ end
62
+
63
+ # Checks equality by comparing each attribute.
64
+ # @param [Object] Object to be compared
65
+ def ==(other)
66
+ return true if self.equal?(other)
67
+ self.class == other.class &&
68
+ query_categorization == other.query_categorization
69
+ end
70
+
71
+ # @see the `==` method
72
+ # @param [Object] Object to be compared
73
+ def eql?(other)
74
+ self == other
75
+ end
76
+
77
+ # Calculates hash code according to all attributes.
78
+ # @return [Integer] Hash code
79
+ def hash
80
+ [query_categorization].hash
81
+ end
82
+
83
+ # Builds the object from hash
84
+ # @param [Hash] attributes Model attributes in the form of hash
85
+ # @return [Object] Returns the model itself
86
+ def self.build_from_hash(attributes)
87
+ return nil unless attributes.is_a?(Hash)
88
+ attributes = attributes.transform_keys(&:to_sym)
89
+ transformed_hash = {}
90
+ types_mapping.each_pair do |key, type|
91
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
92
+ transformed_hash[key.to_sym] = nil
93
+ elsif type =~ /\AArray<(.*)>/i
94
+ # check to ensure the input is an array given that the attribute
95
+ # is documented as an array but the input is not
96
+ if attributes[attribute_map[key]].is_a?(Array)
97
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
98
+ _deserialize(::Regexp.last_match(1), v)
99
+ }
100
+ end
101
+ elsif !attributes[attribute_map[key]].nil?
102
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
103
+ end
104
+ end
105
+
106
+ new(transformed_hash)
107
+ end
108
+
109
+ # Deserializes the data based on type
110
+ # @param string type Data type
111
+ # @param string value Value to be deserialized
112
+ # @return [Object] Deserialized data
113
+ def self._deserialize(type, value)
114
+ case type.to_sym
115
+ when :Time
116
+ Time.parse(value)
117
+ when :Date
118
+ Date.parse(value)
119
+ when :String
120
+ value.to_s
121
+ when :Integer
122
+ value.to_i
123
+ when :Float
124
+ value.to_f
125
+ when :Boolean
126
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
127
+ true
128
+ else
129
+ false
130
+ end
131
+
132
+ when :Object
133
+ # generic object (usually a Hash), return directly
134
+ value
135
+ when /\AArray<(?<inner_type>.+)>\z/
136
+ inner_type = Regexp.last_match[:inner_type]
137
+ value.map { |v| _deserialize(inner_type, v) }
138
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
139
+ k_type = Regexp.last_match[:k_type]
140
+ v_type = Regexp.last_match[:v_type]
141
+ {}.tap do |hash|
142
+ value.each do |k, v|
143
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
144
+ end
145
+ end
146
+ # model
147
+ else
148
+ # models (e.g. Pet) or oneOf
149
+ klass = Algolia::Search.const_get(type)
150
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
151
+ .build_from_hash(value)
152
+ end
153
+ end
154
+
155
+ # Returns the string representation of the object
156
+ # @return [String] String presentation of the object
157
+ def to_s
158
+ to_hash.to_s
159
+ end
160
+
161
+ # to_body is an alias to to_hash (backward compatibility)
162
+ # @return [Hash] Returns the object in the form of hash
163
+ def to_body
164
+ to_hash
165
+ end
166
+
167
+ def to_json(*_args)
168
+ to_hash.to_json
169
+ end
170
+
171
+ # Returns the object in the form of hash
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_hash
174
+ hash = {}
175
+ self.class.attribute_map.each_pair do |attr, param|
176
+ value = send(attr)
177
+ if value.nil?
178
+ is_nullable = self.class.openapi_nullable.include?(attr)
179
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
180
+ end
181
+
182
+ hash[param] = _to_hash(value)
183
+ end
184
+
185
+ hash
186
+ end
187
+
188
+ # Outputs non-array value in the form of hash
189
+ # For object, use to_hash. Otherwise, just return the value
190
+ # @param [Object] value Any valid value
191
+ # @return [Hash] Returns the value in the form of hash
192
+ def _to_hash(value)
193
+ if value.is_a?(Array)
194
+ value.compact.map { |v| _to_hash(v) }
195
+ elsif value.is_a?(Hash)
196
+ {}.tap do |hash|
197
+ value.each { |k, v| hash[k] = _to_hash(v) }
198
+ end
199
+ elsif value.respond_to?(:to_hash)
200
+ value.to_hash
201
+ else
202
+ value
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,207 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
4
+
5
+ require "date"
6
+ require "time"
7
+
8
+ module Algolia
9
+ module Search
10
+ # Additional parameters for Algolia AI features. Used to enable [Query Categorization](https://www.algolia.com/doc/guides/algolia-ai/query-categorization/) and other AI-powered capabilities.
11
+ class SearchExtensions
12
+ attr_accessor :query_categorization
13
+
14
+ # Attribute mapping from ruby-style variable name to JSON key.
15
+ def self.attribute_map
16
+ {
17
+ :query_categorization => :queryCategorization
18
+ }
19
+ end
20
+
21
+ # Attribute type mapping.
22
+ def self.types_mapping
23
+ {
24
+ :query_categorization => :"SearchExtensionsQueryCategorization"
25
+ }
26
+ end
27
+
28
+ # List of attributes with nullable: true
29
+ def self.openapi_nullable
30
+ Set.new(
31
+ []
32
+ )
33
+ end
34
+
35
+ # Initializes the object
36
+ # @param [Hash] attributes Model attributes in the form of hash
37
+ def initialize(attributes = {})
38
+ if (!attributes.is_a?(Hash))
39
+ raise(
40
+ ArgumentError,
41
+ "The input argument (attributes) must be a hash in `Algolia::SearchExtensions` initialize method"
42
+ )
43
+ end
44
+
45
+ # check to see if the attribute exists and convert string to symbol for hash key
46
+ attributes = attributes.each_with_object({}) { |(k, v), h|
47
+ if (!self.class.attribute_map.key?(k.to_sym))
48
+ raise(
49
+ ArgumentError,
50
+ "`#{k}` is not a valid attribute in `Algolia::SearchExtensions`. Please check the name to make sure it's valid. List of attributes: " +
51
+ self.class.attribute_map.keys.inspect
52
+ )
53
+ end
54
+
55
+ h[k.to_sym] = v
56
+ }
57
+
58
+ if attributes.key?(:query_categorization)
59
+ self.query_categorization = attributes[:query_categorization]
60
+ end
61
+ end
62
+
63
+ # Checks equality by comparing each attribute.
64
+ # @param [Object] Object to be compared
65
+ def ==(other)
66
+ return true if self.equal?(other)
67
+ self.class == other.class &&
68
+ query_categorization == other.query_categorization
69
+ end
70
+
71
+ # @see the `==` method
72
+ # @param [Object] Object to be compared
73
+ def eql?(other)
74
+ self == other
75
+ end
76
+
77
+ # Calculates hash code according to all attributes.
78
+ # @return [Integer] Hash code
79
+ def hash
80
+ [query_categorization].hash
81
+ end
82
+
83
+ # Builds the object from hash
84
+ # @param [Hash] attributes Model attributes in the form of hash
85
+ # @return [Object] Returns the model itself
86
+ def self.build_from_hash(attributes)
87
+ return nil unless attributes.is_a?(Hash)
88
+ attributes = attributes.transform_keys(&:to_sym)
89
+ transformed_hash = {}
90
+ types_mapping.each_pair do |key, type|
91
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
92
+ transformed_hash[key.to_sym] = nil
93
+ elsif type =~ /\AArray<(.*)>/i
94
+ # check to ensure the input is an array given that the attribute
95
+ # is documented as an array but the input is not
96
+ if attributes[attribute_map[key]].is_a?(Array)
97
+ transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
98
+ _deserialize(::Regexp.last_match(1), v)
99
+ }
100
+ end
101
+ elsif !attributes[attribute_map[key]].nil?
102
+ transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
103
+ end
104
+ end
105
+
106
+ new(transformed_hash)
107
+ end
108
+
109
+ # Deserializes the data based on type
110
+ # @param string type Data type
111
+ # @param string value Value to be deserialized
112
+ # @return [Object] Deserialized data
113
+ def self._deserialize(type, value)
114
+ case type.to_sym
115
+ when :Time
116
+ Time.parse(value)
117
+ when :Date
118
+ Date.parse(value)
119
+ when :String
120
+ value.to_s
121
+ when :Integer
122
+ value.to_i
123
+ when :Float
124
+ value.to_f
125
+ when :Boolean
126
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
127
+ true
128
+ else
129
+ false
130
+ end
131
+
132
+ when :Object
133
+ # generic object (usually a Hash), return directly
134
+ value
135
+ when /\AArray<(?<inner_type>.+)>\z/
136
+ inner_type = Regexp.last_match[:inner_type]
137
+ value.map { |v| _deserialize(inner_type, v) }
138
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
139
+ k_type = Regexp.last_match[:k_type]
140
+ v_type = Regexp.last_match[:v_type]
141
+ {}.tap do |hash|
142
+ value.each do |k, v|
143
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
144
+ end
145
+ end
146
+ # model
147
+ else
148
+ # models (e.g. Pet) or oneOf
149
+ klass = Algolia::Search.const_get(type)
150
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
151
+ .build_from_hash(value)
152
+ end
153
+ end
154
+
155
+ # Returns the string representation of the object
156
+ # @return [String] String presentation of the object
157
+ def to_s
158
+ to_hash.to_s
159
+ end
160
+
161
+ # to_body is an alias to to_hash (backward compatibility)
162
+ # @return [Hash] Returns the object in the form of hash
163
+ def to_body
164
+ to_hash
165
+ end
166
+
167
+ def to_json(*_args)
168
+ to_hash.to_json
169
+ end
170
+
171
+ # Returns the object in the form of hash
172
+ # @return [Hash] Returns the object in the form of hash
173
+ def to_hash
174
+ hash = {}
175
+ self.class.attribute_map.each_pair do |attr, param|
176
+ value = send(attr)
177
+ if value.nil?
178
+ is_nullable = self.class.openapi_nullable.include?(attr)
179
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
180
+ end
181
+
182
+ hash[param] = _to_hash(value)
183
+ end
184
+
185
+ hash
186
+ end
187
+
188
+ # Outputs non-array value in the form of hash
189
+ # For object, use to_hash. Otherwise, just return the value
190
+ # @param [Object] value Any valid value
191
+ # @return [Hash] Returns the value in the form of hash
192
+ def _to_hash(value)
193
+ if value.is_a?(Array)
194
+ value.compact.map { |v| _to_hash(v) }
195
+ elsif value.is_a?(Hash)
196
+ {}.tap do |hash|
197
+ value.each { |k, v| hash[k] = _to_hash(v) }
198
+ end
199
+ elsif value.respond_to?(:to_hash)
200
+ value.to_hash
201
+ else
202
+ value
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end