Skip to content

Commit 0bdbc19

Browse files
feat(javascript): add replaceAllObjectsWithTransformation (generated)
algolia/api-clients-automation#5008 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 9d5556d commit 0bdbc19

File tree

1 file changed

+235
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)