Skip to content

Commit cb3fca2

Browse files
algolia-botben-kalmusClaraMuller
committed
feat(specs): add compositions deduplication setting (generated)
algolia/api-clients-automation#5418 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Ben Kalmus <[email protected]> Co-authored-by: Clara Muller <[email protected]>
1 parent 12f21d7 commit cb3fca2

File tree

3 files changed

+258
-4
lines changed

3 files changed

+258
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 Composition
10+
class DedupPositioning
11+
HIGHEST = "highest".freeze
12+
HIGHEST_INJECTED = "highestInjected".freeze
13+
14+
def self.all_vars
15+
@all_vars ||= [HIGHEST, HIGHEST_INJECTED].freeze
16+
end
17+
18+
# Builds the enum from string
19+
# @param [String] The enum value in the form of the string
20+
# @return [String] The enum value
21+
def self.build_from_hash(value)
22+
new.build_from_hash(value)
23+
end
24+
25+
# Builds the enum from string
26+
# @param [String] The enum value in the form of the string
27+
# @return [String] The enum value
28+
def build_from_hash(value)
29+
return value if DedupPositioning.all_vars.include?(value)
30+
raise "Invalid ENUM value #{value} for class #DedupPositioning"
31+
end
32+
end
33+
end
34+
end
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
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 Composition
10+
# Deduplication configures the methods used to resolve duplicate items between main search results and injected group results.
11+
class Deduplication
12+
attr_accessor :positioning
13+
14+
# Attribute mapping from ruby-style variable name to JSON key.
15+
def self.attribute_map
16+
{
17+
:positioning => :positioning
18+
}
19+
end
20+
21+
# Attribute type mapping.
22+
def self.types_mapping
23+
{
24+
:positioning => :"DedupPositioning"
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::Deduplication` 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::Deduplication`. 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?(:positioning)
59+
self.positioning = attributes[:positioning]
60+
else
61+
self.positioning = nil
62+
end
63+
end
64+
65+
# Checks equality by comparing each attribute.
66+
# @param [Object] Object to be compared
67+
def ==(other)
68+
return true if self.equal?(other)
69+
self.class == other.class &&
70+
positioning == other.positioning
71+
end
72+
73+
# @see the `==` method
74+
# @param [Object] Object to be compared
75+
def eql?(other)
76+
self == other
77+
end
78+
79+
# Calculates hash code according to all attributes.
80+
# @return [Integer] Hash code
81+
def hash
82+
[positioning].hash
83+
end
84+
85+
# Builds the object from hash
86+
# @param [Hash] attributes Model attributes in the form of hash
87+
# @return [Object] Returns the model itself
88+
def self.build_from_hash(attributes)
89+
return nil unless attributes.is_a?(Hash)
90+
attributes = attributes.transform_keys(&:to_sym)
91+
transformed_hash = {}
92+
types_mapping.each_pair do |key, type|
93+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
94+
transformed_hash[key.to_sym] = nil
95+
elsif type =~ /\AArray<(.*)>/i
96+
# check to ensure the input is an array given that the attribute
97+
# is documented as an array but the input is not
98+
if attributes[attribute_map[key]].is_a?(Array)
99+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
100+
_deserialize(::Regexp.last_match(1), v)
101+
}
102+
end
103+
elsif !attributes[attribute_map[key]].nil?
104+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
105+
end
106+
end
107+
108+
new(transformed_hash)
109+
end
110+
111+
# Deserializes the data based on type
112+
# @param string type Data type
113+
# @param string value Value to be deserialized
114+
# @return [Object] Deserialized data
115+
def self._deserialize(type, value)
116+
case type.to_sym
117+
when :Time
118+
Time.parse(value)
119+
when :Date
120+
Date.parse(value)
121+
when :String
122+
value.to_s
123+
when :Integer
124+
value.to_i
125+
when :Float
126+
value.to_f
127+
when :Boolean
128+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
129+
true
130+
else
131+
false
132+
end
133+
134+
when :Object
135+
# generic object (usually a Hash), return directly
136+
value
137+
when /\AArray<(?<inner_type>.+)>\z/
138+
inner_type = Regexp.last_match[:inner_type]
139+
value.map { |v| _deserialize(inner_type, v) }
140+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
141+
k_type = Regexp.last_match[:k_type]
142+
v_type = Regexp.last_match[:v_type]
143+
{}.tap do |hash|
144+
value.each do |k, v|
145+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
146+
end
147+
end
148+
# model
149+
else
150+
# models (e.g. Pet) or oneOf
151+
klass = Algolia::Composition.const_get(type)
152+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
153+
.build_from_hash(value)
154+
end
155+
end
156+
157+
# Returns the string representation of the object
158+
# @return [String] String presentation of the object
159+
def to_s
160+
to_hash.to_s
161+
end
162+
163+
# to_body is an alias to to_hash (backward compatibility)
164+
# @return [Hash] Returns the object in the form of hash
165+
def to_body
166+
to_hash
167+
end
168+
169+
def to_json(*_args)
170+
to_hash.to_json
171+
end
172+
173+
# Returns the object in the form of hash
174+
# @return [Hash] Returns the object in the form of hash
175+
def to_hash
176+
hash = {}
177+
self.class.attribute_map.each_pair do |attr, param|
178+
value = send(attr)
179+
if value.nil?
180+
is_nullable = self.class.openapi_nullable.include?(attr)
181+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
182+
end
183+
184+
hash[param] = _to_hash(value)
185+
end
186+
187+
hash
188+
end
189+
190+
# Outputs non-array value in the form of hash
191+
# For object, use to_hash. Otherwise, just return the value
192+
# @param [Object] value Any valid value
193+
# @return [Hash] Returns the value in the form of hash
194+
def _to_hash(value)
195+
if value.is_a?(Array)
196+
value.compact.map { |v| _to_hash(v) }
197+
elsif value.is_a?(Hash)
198+
{}.tap do |hash|
199+
value.each { |k, v| hash[k] = _to_hash(v) }
200+
end
201+
elsif value.respond_to?(:to_hash)
202+
value.to_hash
203+
else
204+
value
205+
end
206+
end
207+
208+
end
209+
210+
end
211+
end

lib/algolia/models/composition/injection.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ class Injection
1313
# list of injected items of the current Composition.
1414
attr_accessor :injected_items
1515

16+
attr_accessor :deduplication
17+
1618
# Attribute mapping from ruby-style variable name to JSON key.
1719
def self.attribute_map
1820
{
1921
:main => :main,
20-
:injected_items => :injectedItems
22+
:injected_items => :injectedItems,
23+
:deduplication => :deduplication
2124
}
2225
end
2326

2427
# Attribute type mapping.
2528
def self.types_mapping
2629
{
2730
:main => :"Main",
28-
:injected_items => :"Array<InjectedItem>"
31+
:injected_items => :"Array<InjectedItem>",
32+
:deduplication => :"Deduplication"
2933
}
3034
end
3135

@@ -70,6 +74,10 @@ def initialize(attributes = {})
7074
self.injected_items = value
7175
end
7276
end
77+
78+
if attributes.key?(:deduplication)
79+
self.deduplication = attributes[:deduplication]
80+
end
7381
end
7482

7583
# Checks equality by comparing each attribute.
@@ -78,7 +86,8 @@ def ==(other)
7886
return true if self.equal?(other)
7987
self.class == other.class &&
8088
main == other.main &&
81-
injected_items == other.injected_items
89+
injected_items == other.injected_items &&
90+
deduplication == other.deduplication
8291
end
8392

8493
# @see the `==` method
@@ -90,7 +99,7 @@ def eql?(other)
9099
# Calculates hash code according to all attributes.
91100
# @return [Integer] Hash code
92101
def hash
93-
[main, injected_items].hash
102+
[main, injected_items, deduplication].hash
94103
end
95104

96105
# Builds the object from hash

0 commit comments

Comments
 (0)