Skip to content

Commit 6afcc8a

Browse files
algolia-botClaraMullerFluf22
committed
fix(specs): invalid API format for multi feed in Comp API (generated)
algolia/api-clients-automation#5993 Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com> Co-authored-by: Clara Muller <5667350+ClaraMuller@users.noreply.github.com> Co-authored-by: Thomas Raffray <Fluf22@users.noreply.github.com>
1 parent 65d9db1 commit 6afcc8a

2 files changed

Lines changed: 210 additions & 1 deletion

File tree

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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+
# Feed formatted as an injection.
11+
class FeedInjection
12+
attr_accessor :injection
13+
14+
# Attribute mapping from ruby-style variable name to JSON key.
15+
def self.attribute_map
16+
{
17+
:injection => :injection
18+
}
19+
end
20+
21+
# Attribute type mapping.
22+
def self.types_mapping
23+
{
24+
:injection => :"Injection"
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::FeedInjection` 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::FeedInjection`. 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?(:injection)
59+
self.injection = attributes[:injection]
60+
else
61+
self.injection = 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+
injection == other.injection
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+
[injection].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+
end
208+
end
209+
end

lib/algolia/models/composition/multifeed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def self.attribute_map
2525
# Attribute type mapping.
2626
def self.types_mapping
2727
{
28-
:feeds => :"Hash<String, Injection>",
28+
:feeds => :"Hash<String, FeedInjection>",
2929
:feeds_order => :"Array<String>"
3030
}
3131
end

0 commit comments

Comments
 (0)