Skip to content

Commit 82e6d39

Browse files
algolia-botKalmar99Jonas Kalmar Rønningmillotp
committed
feat(specs): add support for widgets / banners in search for the csharp client (generated)
algolia/api-clients-automation#3870 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Jonas <[email protected]> Co-authored-by: Jonas Kalmar Rønning <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent a505b50 commit 82e6d39

14 files changed

+2588
-8
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
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+
# a search banner with image and url.
9+
class Banner
10+
attr_accessor :image
11+
12+
attr_accessor :link
13+
14+
# Attribute mapping from ruby-style variable name to JSON key.
15+
def self.attribute_map
16+
{
17+
:image => :image,
18+
:link => :link
19+
}
20+
end
21+
22+
# Returns all the JSON keys this model knows about
23+
def self.acceptable_attributes
24+
attribute_map.values
25+
end
26+
27+
# Attribute type mapping.
28+
def self.types_mapping
29+
{
30+
:image => :"BannerImage",
31+
:link => :"BannerLink"
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 ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Banner` initialize method"
47+
end
48+
49+
# check to see if the attribute exists and convert string to symbol for hash key
50+
attributes = attributes.each_with_object({}) { |(k, v), h|
51+
if (!self.class.attribute_map.key?(k.to_sym))
52+
raise(
53+
ArgumentError,
54+
"`#{k}` is not a valid attribute in `Algolia::Banner`. Please check the name to make sure it's valid. List of attributes: " +
55+
self.class.attribute_map.keys.inspect
56+
)
57+
end
58+
59+
h[k.to_sym] = v
60+
}
61+
62+
if attributes.key?(:image)
63+
self.image = attributes[:image]
64+
end
65+
66+
if attributes.key?(:link)
67+
self.link = attributes[:link]
68+
end
69+
end
70+
71+
# Checks equality by comparing each attribute.
72+
# @param [Object] Object to be compared
73+
def ==(other)
74+
return true if self.equal?(other)
75+
self.class == other.class &&
76+
image == other.image &&
77+
link == other.link
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+
[image, link].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::Recommend.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+
215+
end
216+
217+
end
218+
end

0 commit comments

Comments
 (0)