algolia 3.0.0.beta.1 → 3.0.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +9 -7
- data/algolia.gemspec +1 -2
- data/lib/algolia/api/search_client.rb +67 -2
- data/lib/algolia/api_error.rb +2 -2
- data/lib/algolia/models/abtesting/error_base.rb +2 -6
- data/lib/algolia/models/analytics/error_base.rb +2 -6
- data/lib/algolia/models/ingestion/error_base.rb +2 -6
- data/lib/algolia/models/insights/error_base.rb +2 -6
- data/lib/algolia/models/monitoring/error_base.rb +2 -6
- data/lib/algolia/models/personalization/error_base.rb +2 -6
- data/lib/algolia/models/query-suggestions/error_base.rb +2 -6
- data/lib/algolia/models/recommend/base_search_response.rb +2 -6
- data/lib/algolia/models/recommend/error_base.rb +2 -6
- data/lib/algolia/models/recommend/facet_filters.rb +1 -1
- data/lib/algolia/models/recommend/fallback_params.rb +1 -3
- data/lib/algolia/models/recommend/numeric_filters.rb +1 -1
- data/lib/algolia/models/recommend/optional_filters.rb +1 -1
- data/lib/algolia/models/recommend/ranking_info.rb +0 -6
- data/lib/algolia/models/recommend/re_ranking_apply_filter.rb +1 -1
- data/lib/algolia/models/recommend/recommend_hit.rb +2 -6
- data/lib/algolia/models/recommend/search_params.rb +1 -3
- data/lib/algolia/models/recommend/search_params_object.rb +1 -3
- data/lib/algolia/models/recommend/tag_filters.rb +1 -1
- data/lib/algolia/models/search/base_search_response.rb +2 -6
- data/lib/algolia/models/search/browse_params_object.rb +1 -3
- data/lib/algolia/models/search/consequence_params.rb +1 -3
- data/lib/algolia/models/search/dictionary_entry.rb +2 -6
- data/lib/algolia/models/search/error_base.rb +2 -6
- data/lib/algolia/models/search/facet_filters.rb +1 -1
- data/lib/algolia/models/search/hit.rb +2 -6
- data/lib/algolia/models/search/index_settings.rb +1 -3
- data/lib/algolia/models/search/numeric_filters.rb +1 -1
- data/lib/algolia/models/search/optional_filters.rb +1 -1
- data/lib/algolia/models/search/ranking_info.rb +0 -6
- data/lib/algolia/models/search/re_ranking_apply_filter.rb +1 -1
- data/lib/algolia/models/search/replace_all_objects_response.rb +223 -0
- data/lib/algolia/models/search/search_for_facet_values_response.rb +1 -1
- data/lib/algolia/models/search/search_for_facets.rb +1 -3
- data/lib/algolia/models/search/search_for_hits.rb +1 -3
- data/lib/algolia/models/search/search_hits.rb +2 -6
- data/lib/algolia/models/search/search_params_object.rb +1 -3
- data/lib/algolia/models/search/search_response.rb +2 -6
- data/lib/algolia/models/search/search_synonyms_response.rb +2 -6
- data/lib/algolia/models/search/tag_filters.rb +1 -1
- data/lib/algolia/models/usage/error_base.rb +2 -6
- data/lib/algolia/version.rb +1 -1
- metadata +5 -7
- data/lib/algolia/models/recommend/mixed_search_filters.rb +0 -96
- data/lib/algolia/models/search/mixed_search_filters.rb +0 -96
@@ -0,0 +1,223 @@
|
|
1
|
+
# 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.
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
module Algolia
|
7
|
+
module Search
|
8
|
+
class ReplaceAllObjectsResponse
|
9
|
+
attr_accessor :copy_operation_response
|
10
|
+
|
11
|
+
# The response of the `batch` request(s).
|
12
|
+
attr_accessor :batch_responses
|
13
|
+
|
14
|
+
attr_accessor :move_operation_response
|
15
|
+
|
16
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
17
|
+
def self.attribute_map
|
18
|
+
{
|
19
|
+
:copy_operation_response => :copyOperationResponse,
|
20
|
+
:batch_responses => :batchResponses,
|
21
|
+
:move_operation_response => :moveOperationResponse
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns all the JSON keys this model knows about
|
26
|
+
def self.acceptable_attributes
|
27
|
+
attribute_map.values
|
28
|
+
end
|
29
|
+
|
30
|
+
# Attribute type mapping.
|
31
|
+
def self.types_mapping
|
32
|
+
{
|
33
|
+
:copy_operation_response => :UpdatedAtResponse,
|
34
|
+
:batch_responses => :'Array<BatchResponse>',
|
35
|
+
:move_operation_response => :UpdatedAtResponse
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# List of attributes with nullable: true
|
40
|
+
def self.openapi_nullable
|
41
|
+
Set.new([])
|
42
|
+
end
|
43
|
+
|
44
|
+
# Initializes the object
|
45
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
46
|
+
def initialize(attributes = {})
|
47
|
+
unless attributes.is_a?(Hash)
|
48
|
+
raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::ReplaceAllObjectsResponse` initialize method"
|
49
|
+
end
|
50
|
+
|
51
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
52
|
+
attributes = attributes.each_with_object({}) do |(k, v), h|
|
53
|
+
unless self.class.attribute_map.key?(k.to_sym)
|
54
|
+
raise ArgumentError,
|
55
|
+
"`#{k}` is not a valid attribute in `Algolia::ReplaceAllObjectsResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
56
|
+
end
|
57
|
+
|
58
|
+
h[k.to_sym] = v
|
59
|
+
end
|
60
|
+
|
61
|
+
if attributes.key?(:copy_operation_response)
|
62
|
+
self.copy_operation_response = attributes[:copy_operation_response]
|
63
|
+
else
|
64
|
+
self.copy_operation_response = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
if attributes.key?(:batch_responses)
|
68
|
+
if (value = attributes[:batch_responses]).is_a?(Array)
|
69
|
+
self.batch_responses = value
|
70
|
+
end
|
71
|
+
else
|
72
|
+
self.batch_responses = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
if attributes.key?(:move_operation_response)
|
76
|
+
self.move_operation_response = attributes[:move_operation_response]
|
77
|
+
else
|
78
|
+
self.move_operation_response = nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Checks equality by comparing each attribute.
|
83
|
+
# @param [Object] Object to be compared
|
84
|
+
def ==(other)
|
85
|
+
return true if equal?(other)
|
86
|
+
|
87
|
+
self.class == other.class &&
|
88
|
+
copy_operation_response == other.copy_operation_response &&
|
89
|
+
batch_responses == other.batch_responses &&
|
90
|
+
move_operation_response == other.move_operation_response
|
91
|
+
end
|
92
|
+
|
93
|
+
# @see the `==` method
|
94
|
+
# @param [Object] Object to be compared
|
95
|
+
def eql?(other)
|
96
|
+
self == other
|
97
|
+
end
|
98
|
+
|
99
|
+
# Calculates hash code according to all attributes.
|
100
|
+
# @return [Integer] Hash code
|
101
|
+
def hash
|
102
|
+
[copy_operation_response, batch_responses, move_operation_response].hash
|
103
|
+
end
|
104
|
+
|
105
|
+
# Builds the object from hash
|
106
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
107
|
+
# @return [Object] Returns the model itself
|
108
|
+
def self.build_from_hash(attributes)
|
109
|
+
return nil unless attributes.is_a?(Hash)
|
110
|
+
|
111
|
+
attributes = attributes.transform_keys(&:to_sym)
|
112
|
+
transformed_hash = {}
|
113
|
+
types_mapping.each_pair do |key, type|
|
114
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
115
|
+
transformed_hash[key.to_sym] = nil
|
116
|
+
elsif type =~ /\AArray<(.*)>/i
|
117
|
+
# check to ensure the input is an array given that the attribute
|
118
|
+
# is documented as an array but the input is not
|
119
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
120
|
+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
|
121
|
+
end
|
122
|
+
elsif !attributes[attribute_map[key]].nil?
|
123
|
+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
new(transformed_hash)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Deserializes the data based on type
|
130
|
+
# @param string type Data type
|
131
|
+
# @param string value Value to be deserialized
|
132
|
+
# @return [Object] Deserialized data
|
133
|
+
def self._deserialize(type, value)
|
134
|
+
case type.to_sym
|
135
|
+
when :Time
|
136
|
+
Time.parse(value)
|
137
|
+
when :Date
|
138
|
+
Date.parse(value)
|
139
|
+
when :String
|
140
|
+
value.to_s
|
141
|
+
when :Integer
|
142
|
+
value.to_i
|
143
|
+
when :Float
|
144
|
+
value.to_f
|
145
|
+
when :Boolean
|
146
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
when :Object
|
152
|
+
# generic object (usually a Hash), return directly
|
153
|
+
value
|
154
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
155
|
+
inner_type = Regexp.last_match[:inner_type]
|
156
|
+
value.map { |v| _deserialize(inner_type, v) }
|
157
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
158
|
+
k_type = Regexp.last_match[:k_type]
|
159
|
+
v_type = Regexp.last_match[:v_type]
|
160
|
+
{}.tap do |hash|
|
161
|
+
value.each do |k, v|
|
162
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
else # model
|
166
|
+
# models (e.g. Pet) or oneOf
|
167
|
+
klass = Algolia::Search.const_get(type)
|
168
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns the string representation of the object
|
173
|
+
# @return [String] String presentation of the object
|
174
|
+
def to_s
|
175
|
+
to_hash.to_s
|
176
|
+
end
|
177
|
+
|
178
|
+
# to_body is an alias to to_hash (backward compatibility)
|
179
|
+
# @return [Hash] Returns the object in the form of hash
|
180
|
+
def to_body
|
181
|
+
to_hash
|
182
|
+
end
|
183
|
+
|
184
|
+
def to_json(*_args)
|
185
|
+
to_hash.to_json
|
186
|
+
end
|
187
|
+
|
188
|
+
# Returns the object in the form of hash
|
189
|
+
# @return [Hash] Returns the object in the form of hash
|
190
|
+
def to_hash
|
191
|
+
hash = {}
|
192
|
+
self.class.attribute_map.each_pair do |attr, param|
|
193
|
+
value = send(attr)
|
194
|
+
if value.nil?
|
195
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
196
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
197
|
+
end
|
198
|
+
|
199
|
+
hash[param] = _to_hash(value)
|
200
|
+
end
|
201
|
+
hash
|
202
|
+
end
|
203
|
+
|
204
|
+
# Outputs non-array value in the form of hash
|
205
|
+
# For object, use to_hash. Otherwise, just return the value
|
206
|
+
# @param [Object] value Any valid value
|
207
|
+
# @return [Hash] Returns the value in the form of hash
|
208
|
+
def _to_hash(value)
|
209
|
+
if value.is_a?(Array)
|
210
|
+
value.compact.map { |v| _to_hash(v) }
|
211
|
+
elsif value.is_a?(Hash)
|
212
|
+
{}.tap do |hash|
|
213
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
214
|
+
end
|
215
|
+
elsif value.respond_to? :to_hash
|
216
|
+
value.to_hash
|
217
|
+
else
|
218
|
+
value
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -9,7 +9,7 @@ module Algolia
|
|
9
9
|
# Matching facet values.
|
10
10
|
attr_accessor :facet_hits
|
11
11
|
|
12
|
-
#
|
12
|
+
# Whether the facet count is exhaustive (true) or approximate (false). For more information, see [Why are my facet and hit counts not accurate](https://support.algolia.com/hc/en-us/articles/4406975248145-Why-are-my-facet-and-hit-counts-not-accurate-).
|
13
13
|
attr_accessor :exhaustive_facets_count
|
14
14
|
|
15
15
|
# Time the server took to process the request, in milliseconds.
|
@@ -122,12 +122,8 @@ module Algolia
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
125
|
-
#
|
126
|
-
|
127
|
-
@additional_properties.each_pair do |k, v|
|
128
|
-
transformed_hash[k.to_sym] = v
|
129
|
-
end
|
130
|
-
end
|
125
|
+
# add extra attribute to transformed_hash
|
126
|
+
transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
|
131
127
|
new(transformed_hash)
|
132
128
|
end
|
133
129
|
|
@@ -483,12 +483,8 @@ module Algolia
|
|
483
483
|
end
|
484
484
|
end
|
485
485
|
|
486
|
-
#
|
487
|
-
|
488
|
-
@additional_properties.each_pair do |k, v|
|
489
|
-
transformed_hash[k.to_sym] = v
|
490
|
-
end
|
491
|
-
end
|
486
|
+
# add extra attribute to transformed_hash
|
487
|
+
transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
|
492
488
|
new(transformed_hash)
|
493
489
|
end
|
494
490
|
|
@@ -110,12 +110,8 @@ module Algolia
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
#
|
114
|
-
|
115
|
-
@additional_properties.each_pair do |k, v|
|
116
|
-
transformed_hash[k.to_sym] = v
|
117
|
-
end
|
118
|
-
end
|
113
|
+
# add extra attribute to transformed_hash
|
114
|
+
transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
|
119
115
|
new(transformed_hash)
|
120
116
|
end
|
121
117
|
|
@@ -94,12 +94,8 @@ module Algolia
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
#
|
98
|
-
|
99
|
-
@additional_properties.each_pair do |k, v|
|
100
|
-
transformed_hash[k.to_sym] = v
|
101
|
-
end
|
102
|
-
end
|
97
|
+
# add extra attribute to transformed_hash
|
98
|
+
transformed_hash.merge!(attributes.reject { |k, _| attribute_map.key?(k.to_sym) })
|
103
99
|
new(transformed_hash)
|
104
100
|
end
|
105
101
|
|
data/lib/algolia/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# 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.
|
2
2
|
|
3
3
|
module Algolia
|
4
|
-
VERSION = '3.0.0.beta.
|
4
|
+
VERSION = '3.0.0.beta.3'.freeze
|
5
5
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algolia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.beta.
|
4
|
+
version: 3.0.0.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- https://alg.li/support
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -107,8 +107,7 @@ dependencies:
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
description: A simple Ruby client for the algolia.com REST API
|
110
|
-
email:
|
111
|
-
- support@algolia.com
|
110
|
+
email:
|
112
111
|
executables: []
|
113
112
|
extensions: []
|
114
113
|
extra_rdoc_files: []
|
@@ -450,7 +449,6 @@ files:
|
|
450
449
|
- lib/algolia/models/recommend/looking_similar_query.rb
|
451
450
|
- lib/algolia/models/recommend/match_level.rb
|
452
451
|
- lib/algolia/models/recommend/matched_geo_location.rb
|
453
|
-
- lib/algolia/models/recommend/mixed_search_filters.rb
|
454
452
|
- lib/algolia/models/recommend/mode.rb
|
455
453
|
- lib/algolia/models/recommend/numeric_filters.rb
|
456
454
|
- lib/algolia/models/recommend/optional_filters.rb
|
@@ -590,7 +588,6 @@ files:
|
|
590
588
|
- lib/algolia/models/search/log_type.rb
|
591
589
|
- lib/algolia/models/search/match_level.rb
|
592
590
|
- lib/algolia/models/search/matched_geo_location.rb
|
593
|
-
- lib/algolia/models/search/mixed_search_filters.rb
|
594
591
|
- lib/algolia/models/search/mode.rb
|
595
592
|
- lib/algolia/models/search/multiple_batch_request.rb
|
596
593
|
- lib/algolia/models/search/multiple_batch_response.rb
|
@@ -613,6 +610,7 @@ files:
|
|
613
610
|
- lib/algolia/models/search/remove_user_id_response.rb
|
614
611
|
- lib/algolia/models/search/remove_words_if_no_results.rb
|
615
612
|
- lib/algolia/models/search/rendering_content.rb
|
613
|
+
- lib/algolia/models/search/replace_all_objects_response.rb
|
616
614
|
- lib/algolia/models/search/replace_source_response.rb
|
617
615
|
- lib/algolia/models/search/rule.rb
|
618
616
|
- lib/algolia/models/search/save_object_response.rb
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# 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.
|
2
|
-
|
3
|
-
require 'date'
|
4
|
-
require 'time'
|
5
|
-
|
6
|
-
module Algolia
|
7
|
-
module Recommend
|
8
|
-
module MixedSearchFilters
|
9
|
-
class << self
|
10
|
-
# List of class defined in oneOf (OpenAPI v3)
|
11
|
-
def openapi_one_of
|
12
|
-
[
|
13
|
-
:'Array<String>',
|
14
|
-
:String
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
# Builds the object
|
19
|
-
# @param [Mixed] Data to be matched against the list of oneOf items
|
20
|
-
# @return [Object] Returns the model or the data itself
|
21
|
-
def build(data)
|
22
|
-
# Go through the list of oneOf items and attempt to identify the appropriate one.
|
23
|
-
# Note:
|
24
|
-
# - We do not attempt to check whether exactly one item matches.
|
25
|
-
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
|
26
|
-
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
|
27
|
-
# - TODO: scalar values are de facto behaving as if they were nullable.
|
28
|
-
# - TODO: logging when debugging is set.
|
29
|
-
openapi_one_of.each do |klass|
|
30
|
-
next if klass == :AnyType # "nullable: true"
|
31
|
-
|
32
|
-
typed_data = find_and_cast_into_type(klass, data)
|
33
|
-
return typed_data if typed_data
|
34
|
-
rescue # rescue all errors so we keep iterating even if the current item lookup raises
|
35
|
-
end
|
36
|
-
|
37
|
-
openapi_one_of.include?(:AnyType) ? data : nil
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
SchemaMismatchError = Class.new(StandardError)
|
43
|
-
|
44
|
-
# NOTE: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
|
45
|
-
def find_and_cast_into_type(klass, data)
|
46
|
-
return if data.nil?
|
47
|
-
|
48
|
-
case klass.to_s
|
49
|
-
when 'Boolean'
|
50
|
-
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
|
51
|
-
when 'Float'
|
52
|
-
return data if data.instance_of?(Float)
|
53
|
-
when 'Integer'
|
54
|
-
return data if data.instance_of?(Integer)
|
55
|
-
when 'Time'
|
56
|
-
return Time.parse(data)
|
57
|
-
when 'Date'
|
58
|
-
return Date.parse(data)
|
59
|
-
when 'String'
|
60
|
-
return data if data.instance_of?(String)
|
61
|
-
when 'Object' # "type: object"
|
62
|
-
return data if data.instance_of?(Hash)
|
63
|
-
when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
|
64
|
-
if data.instance_of?(Array)
|
65
|
-
sub_type = Regexp.last_match[:sub_type]
|
66
|
-
return data.map { |item| find_and_cast_into_type(sub_type, item) }
|
67
|
-
end
|
68
|
-
when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
|
69
|
-
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
|
70
|
-
sub_type = Regexp.last_match[:sub_type]
|
71
|
-
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
|
72
|
-
end
|
73
|
-
else # model
|
74
|
-
const = Algolia::Recommend.const_get(klass)
|
75
|
-
if const
|
76
|
-
if const.respond_to?(:openapi_one_of) # nested oneOf model
|
77
|
-
model = const.build(data)
|
78
|
-
else
|
79
|
-
# raise if data contains keys that are not known to the model
|
80
|
-
raise unless (data.keys - const.acceptable_attributes).empty?
|
81
|
-
|
82
|
-
model = const.build_from_hash(data)
|
83
|
-
end
|
84
|
-
|
85
|
-
return model if model
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
raise # if no match by now, raise
|
90
|
-
rescue
|
91
|
-
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
# 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.
|
2
|
-
|
3
|
-
require 'date'
|
4
|
-
require 'time'
|
5
|
-
|
6
|
-
module Algolia
|
7
|
-
module Search
|
8
|
-
module MixedSearchFilters
|
9
|
-
class << self
|
10
|
-
# List of class defined in oneOf (OpenAPI v3)
|
11
|
-
def openapi_one_of
|
12
|
-
[
|
13
|
-
:'Array<String>',
|
14
|
-
:String
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
# Builds the object
|
19
|
-
# @param [Mixed] Data to be matched against the list of oneOf items
|
20
|
-
# @return [Object] Returns the model or the data itself
|
21
|
-
def build(data)
|
22
|
-
# Go through the list of oneOf items and attempt to identify the appropriate one.
|
23
|
-
# Note:
|
24
|
-
# - We do not attempt to check whether exactly one item matches.
|
25
|
-
# - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
|
26
|
-
# due to the way the deserialization is made in the base_object template (it just casts without verifying).
|
27
|
-
# - TODO: scalar values are de facto behaving as if they were nullable.
|
28
|
-
# - TODO: logging when debugging is set.
|
29
|
-
openapi_one_of.each do |klass|
|
30
|
-
next if klass == :AnyType # "nullable: true"
|
31
|
-
|
32
|
-
typed_data = find_and_cast_into_type(klass, data)
|
33
|
-
return typed_data if typed_data
|
34
|
-
rescue # rescue all errors so we keep iterating even if the current item lookup raises
|
35
|
-
end
|
36
|
-
|
37
|
-
openapi_one_of.include?(:AnyType) ? data : nil
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
SchemaMismatchError = Class.new(StandardError)
|
43
|
-
|
44
|
-
# NOTE: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
|
45
|
-
def find_and_cast_into_type(klass, data)
|
46
|
-
return if data.nil?
|
47
|
-
|
48
|
-
case klass.to_s
|
49
|
-
when 'Boolean'
|
50
|
-
return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
|
51
|
-
when 'Float'
|
52
|
-
return data if data.instance_of?(Float)
|
53
|
-
when 'Integer'
|
54
|
-
return data if data.instance_of?(Integer)
|
55
|
-
when 'Time'
|
56
|
-
return Time.parse(data)
|
57
|
-
when 'Date'
|
58
|
-
return Date.parse(data)
|
59
|
-
when 'String'
|
60
|
-
return data if data.instance_of?(String)
|
61
|
-
when 'Object' # "type: object"
|
62
|
-
return data if data.instance_of?(Hash)
|
63
|
-
when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
|
64
|
-
if data.instance_of?(Array)
|
65
|
-
sub_type = Regexp.last_match[:sub_type]
|
66
|
-
return data.map { |item| find_and_cast_into_type(sub_type, item) }
|
67
|
-
end
|
68
|
-
when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
|
69
|
-
if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
|
70
|
-
sub_type = Regexp.last_match[:sub_type]
|
71
|
-
return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
|
72
|
-
end
|
73
|
-
else # model
|
74
|
-
const = Algolia::Search.const_get(klass)
|
75
|
-
if const
|
76
|
-
if const.respond_to?(:openapi_one_of) # nested oneOf model
|
77
|
-
model = const.build(data)
|
78
|
-
else
|
79
|
-
# raise if data contains keys that are not known to the model
|
80
|
-
raise unless (data.keys - const.acceptable_attributes).empty?
|
81
|
-
|
82
|
-
model = const.build_from_hash(data)
|
83
|
-
end
|
84
|
-
|
85
|
-
return model if model
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
raise # if no match by now, raise
|
90
|
-
rescue
|
91
|
-
raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|