Skip to content

Commit 2812d2f

Browse files
feat(specs): introduce recommend source in Comp API client (generated)
algolia/api-clients-automation#6227 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Clara Muller <5667350+ClaraMuller@users.noreply.github.com>
1 parent 0ee21f3 commit 2812d2f

6 files changed

Lines changed: 551 additions & 10 deletions

File tree

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

lib/algolia/models/composition/injected_item_source.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class << self
1313
def openapi_one_of
1414
[
1515
:"InjectedItemExternalSource",
16+
:"InjectedItemRecommendSource",
1617
:"InjectedItemSearchSource"
1718
]
1819
end

lib/algolia/models/composition/main_recommend.rb

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,37 @@
88
module Algolia
99
module Composition
1010
class MainRecommend
11-
# Targeted index name.
12-
attr_accessor :index
11+
# Index to retrieve recommendations from.
12+
attr_accessor :index_name
13+
14+
attr_accessor :model
15+
16+
# Minimum score a recommendation must have to be included.
17+
attr_accessor :threshold
18+
19+
attr_accessor :query_parameters
20+
21+
attr_accessor :fallback_parameters
1322

1423
# Attribute mapping from ruby-style variable name to JSON key.
1524
def self.attribute_map
1625
{
17-
:index => :index
26+
:index_name => :indexName,
27+
:model => :model,
28+
:threshold => :threshold,
29+
:query_parameters => :queryParameters,
30+
:fallback_parameters => :fallbackParameters
1831
}
1932
end
2033

2134
# Attribute type mapping.
2235
def self.types_mapping
2336
{
24-
:index => :"String"
37+
:index_name => :"String",
38+
:model => :"Model",
39+
:threshold => :"Integer",
40+
:query_parameters => :"MainInjectionQueryParameters",
41+
:fallback_parameters => :"MainInjectionQueryParameters"
2542
}
2643
end
2744

@@ -55,10 +72,30 @@ def initialize(attributes = {})
5572
h[k.to_sym] = v
5673
}
5774

58-
if attributes.key?(:index)
59-
self.index = attributes[:index]
75+
if attributes.key?(:index_name)
76+
self.index_name = attributes[:index_name]
77+
else
78+
self.index_name = nil
79+
end
80+
81+
if attributes.key?(:model)
82+
self.model = attributes[:model]
6083
else
61-
self.index = nil
84+
self.model = nil
85+
end
86+
87+
if attributes.key?(:threshold)
88+
self.threshold = attributes[:threshold]
89+
else
90+
self.threshold = nil
91+
end
92+
93+
if attributes.key?(:query_parameters)
94+
self.query_parameters = attributes[:query_parameters]
95+
end
96+
97+
if attributes.key?(:fallback_parameters)
98+
self.fallback_parameters = attributes[:fallback_parameters]
6299
end
63100
end
64101

@@ -67,7 +104,11 @@ def initialize(attributes = {})
67104
def ==(other)
68105
return true if self.equal?(other)
69106
self.class == other.class &&
70-
index == other.index
107+
index_name == other.index_name &&
108+
model == other.model &&
109+
threshold == other.threshold &&
110+
query_parameters == other.query_parameters &&
111+
fallback_parameters == other.fallback_parameters
71112
end
72113

73114
# @see the `==` method
@@ -79,7 +120,7 @@ def eql?(other)
79120
# Calculates hash code according to all attributes.
80121
# @return [Integer] Hash code
81122
def hash
82-
[index].hash
123+
[index_name, model, threshold, query_parameters, fallback_parameters].hash
83124
end
84125

85126
# Builds the object from hash

lib/algolia/models/composition/main_search.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module Algolia
99
module Composition
1010
class MainSearch
11-
# Targeted index name.
11+
# Index to retrieve search results from.
1212
attr_accessor :index
1313

1414
attr_accessor :params
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 Model
11+
TRENDING_ITEMS = "trending-items".freeze
12+
13+
def self.all_vars
14+
@all_vars ||= [TRENDING_ITEMS].freeze
15+
end
16+
17+
# Builds the enum from string
18+
# @param [String] The enum value in the form of the string
19+
# @return [String] The enum value
20+
def self.build_from_hash(value)
21+
new.build_from_hash(value)
22+
end
23+
24+
# Builds the enum from string
25+
# @param [String] The enum value in the form of the string
26+
# @return [String] The enum value
27+
def build_from_hash(value)
28+
return value if Model.all_vars.include?(value)
29+
raise "Invalid ENUM value #{value} for class #Model"
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)