Skip to content

Commit 6bb0965

Browse files
feat(specs): add with transformation helpers (generated)
algolia/api-clients-automation#4931 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 24d755a commit 6bb0965

File tree

5 files changed

+623
-3
lines changed

5 files changed

+623
-3
lines changed

lib/algolia/models/ingestion/watch_response.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class WatchResponse
1414
# Universally unique identifier (UUID) of an event.
1515
attr_accessor :event_id
1616

17-
# when used with discovering or validating sources, the sampled data of your source is returned.
17+
# This field is always null when used with the Push endpoint. When used for a source discover or source validate run, it will include the sampled data of the source.
1818
attr_accessor :data
1919

20-
# in case of error, observability events will be added to the response, if any.
20+
# in case of error, observability events will be added to the response.
2121
attr_accessor :events
2222

23-
# a message describing the outcome of a validate run.
23+
# a message describing the outcome of the operation that has been ran (push, discover or validate) run.
2424
attr_accessor :message
2525

2626
# Date of creation in RFC 3339 format.

lib/algolia/models/search/event.rb

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
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+
# An event describe a step of the task execution flow..
11+
class Event
12+
# Universally unique identifier (UUID) of an event.
13+
attr_accessor :event_id
14+
15+
# Universally unique identifier (UUID) of a task run.
16+
attr_accessor :run_id
17+
18+
attr_accessor :status
19+
20+
attr_accessor :type
21+
22+
# The extracted record batch size.
23+
attr_accessor :batch_size
24+
25+
attr_accessor :data
26+
27+
# Date of publish RFC 3339 format.
28+
attr_accessor :published_at
29+
30+
# Attribute mapping from ruby-style variable name to JSON key.
31+
def self.attribute_map
32+
{
33+
:event_id => :eventID,
34+
:run_id => :runID,
35+
:status => :status,
36+
:type => :type,
37+
:batch_size => :batchSize,
38+
:data => :data,
39+
:published_at => :publishedAt
40+
}
41+
end
42+
43+
# Attribute type mapping.
44+
def self.types_mapping
45+
{
46+
:event_id => :"String",
47+
:run_id => :"String",
48+
:status => :"EventStatus",
49+
:type => :"EventType",
50+
:batch_size => :"Integer",
51+
:data => :"Hash<String, Object>",
52+
:published_at => :"String"
53+
}
54+
end
55+
56+
# List of attributes with nullable: true
57+
def self.openapi_nullable
58+
Set.new(
59+
[
60+
:status,
61+
:data
62+
]
63+
)
64+
end
65+
66+
# Initializes the object
67+
# @param [Hash] attributes Model attributes in the form of hash
68+
def initialize(attributes = {})
69+
if (!attributes.is_a?(Hash))
70+
raise ArgumentError, "The input argument (attributes) must be a hash in `Algolia::Event` initialize method"
71+
end
72+
73+
# check to see if the attribute exists and convert string to symbol for hash key
74+
attributes = attributes.each_with_object({}) { |(k, v), h|
75+
if (!self.class.attribute_map.key?(k.to_sym))
76+
raise(
77+
ArgumentError,
78+
"`#{k}` is not a valid attribute in `Algolia::Event`. Please check the name to make sure it's valid. List of attributes: " +
79+
self.class.attribute_map.keys.inspect
80+
)
81+
end
82+
83+
h[k.to_sym] = v
84+
}
85+
86+
if attributes.key?(:event_id)
87+
self.event_id = attributes[:event_id]
88+
else
89+
self.event_id = nil
90+
end
91+
92+
if attributes.key?(:run_id)
93+
self.run_id = attributes[:run_id]
94+
else
95+
self.run_id = nil
96+
end
97+
98+
if attributes.key?(:status)
99+
self.status = attributes[:status]
100+
else
101+
self.status = nil
102+
end
103+
104+
if attributes.key?(:type)
105+
self.type = attributes[:type]
106+
else
107+
self.type = nil
108+
end
109+
110+
if attributes.key?(:batch_size)
111+
self.batch_size = attributes[:batch_size]
112+
else
113+
self.batch_size = nil
114+
end
115+
116+
if attributes.key?(:data)
117+
if (value = attributes[:data]).is_a?(Hash)
118+
self.data = value
119+
end
120+
end
121+
122+
if attributes.key?(:published_at)
123+
self.published_at = attributes[:published_at]
124+
else
125+
self.published_at = nil
126+
end
127+
end
128+
129+
# Checks equality by comparing each attribute.
130+
# @param [Object] Object to be compared
131+
def ==(other)
132+
return true if self.equal?(other)
133+
self.class == other.class &&
134+
event_id == other.event_id &&
135+
run_id == other.run_id &&
136+
status == other.status &&
137+
type == other.type &&
138+
batch_size == other.batch_size &&
139+
data == other.data &&
140+
published_at == other.published_at
141+
end
142+
143+
# @see the `==` method
144+
# @param [Object] Object to be compared
145+
def eql?(other)
146+
self == other
147+
end
148+
149+
# Calculates hash code according to all attributes.
150+
# @return [Integer] Hash code
151+
def hash
152+
[event_id, run_id, status, type, batch_size, data, published_at].hash
153+
end
154+
155+
# Builds the object from hash
156+
# @param [Hash] attributes Model attributes in the form of hash
157+
# @return [Object] Returns the model itself
158+
def self.build_from_hash(attributes)
159+
return nil unless attributes.is_a?(Hash)
160+
attributes = attributes.transform_keys(&:to_sym)
161+
transformed_hash = {}
162+
types_mapping.each_pair do |key, type|
163+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
164+
transformed_hash[key.to_sym] = nil
165+
elsif type =~ /\AArray<(.*)>/i
166+
# check to ensure the input is an array given that the attribute
167+
# is documented as an array but the input is not
168+
if attributes[attribute_map[key]].is_a?(Array)
169+
transformed_hash[key.to_sym] = attributes[attribute_map[key]].map { |v|
170+
_deserialize(::Regexp.last_match(1), v)
171+
}
172+
end
173+
elsif !attributes[attribute_map[key]].nil?
174+
transformed_hash[key.to_sym] = _deserialize(type, attributes[attribute_map[key]])
175+
end
176+
end
177+
178+
new(transformed_hash)
179+
end
180+
181+
# Deserializes the data based on type
182+
# @param string type Data type
183+
# @param string value Value to be deserialized
184+
# @return [Object] Deserialized data
185+
def self._deserialize(type, value)
186+
case type.to_sym
187+
when :Time
188+
Time.parse(value)
189+
when :Date
190+
Date.parse(value)
191+
when :String
192+
value.to_s
193+
when :Integer
194+
value.to_i
195+
when :Float
196+
value.to_f
197+
when :Boolean
198+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
199+
true
200+
else
201+
false
202+
end
203+
204+
when :Object
205+
# generic object (usually a Hash), return directly
206+
value
207+
when /\AArray<(?<inner_type>.+)>\z/
208+
inner_type = Regexp.last_match[:inner_type]
209+
value.map { |v| _deserialize(inner_type, v) }
210+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
211+
k_type = Regexp.last_match[:k_type]
212+
v_type = Regexp.last_match[:v_type]
213+
{}.tap do |hash|
214+
value.each do |k, v|
215+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
216+
end
217+
end
218+
# model
219+
else
220+
# models (e.g. Pet) or oneOf
221+
klass = Algolia::Search.const_get(type)
222+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass
223+
.build_from_hash(value)
224+
end
225+
end
226+
227+
# Returns the string representation of the object
228+
# @return [String] String presentation of the object
229+
def to_s
230+
to_hash.to_s
231+
end
232+
233+
# to_body is an alias to to_hash (backward compatibility)
234+
# @return [Hash] Returns the object in the form of hash
235+
def to_body
236+
to_hash
237+
end
238+
239+
def to_json(*_args)
240+
to_hash.to_json
241+
end
242+
243+
# Returns the object in the form of hash
244+
# @return [Hash] Returns the object in the form of hash
245+
def to_hash
246+
hash = {}
247+
self.class.attribute_map.each_pair do |attr, param|
248+
value = send(attr)
249+
if value.nil?
250+
is_nullable = self.class.openapi_nullable.include?(attr)
251+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
252+
end
253+
254+
hash[param] = _to_hash(value)
255+
end
256+
257+
hash
258+
end
259+
260+
# Outputs non-array value in the form of hash
261+
# For object, use to_hash. Otherwise, just return the value
262+
# @param [Object] value Any valid value
263+
# @return [Hash] Returns the value in the form of hash
264+
def _to_hash(value)
265+
if value.is_a?(Array)
266+
value.compact.map { |v| _to_hash(v) }
267+
elsif value.is_a?(Hash)
268+
{}.tap do |hash|
269+
value.each { |k, v| hash[k] = _to_hash(v) }
270+
end
271+
elsif value.respond_to?(:to_hash)
272+
value.to_hash
273+
else
274+
value
275+
end
276+
end
277+
278+
end
279+
280+
end
281+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 EventStatus
11+
CREATED = "created".freeze
12+
STARTED = "started".freeze
13+
RETRIED = "retried".freeze
14+
FAILED = "failed".freeze
15+
SUCCEEDED = "succeeded".freeze
16+
CRITICAL = "critical".freeze
17+
18+
def self.all_vars
19+
@all_vars ||= [CREATED, STARTED, RETRIED, FAILED, SUCCEEDED, CRITICAL].freeze
20+
end
21+
22+
# Builds the enum from string
23+
# @param [String] The enum value in the form of the string
24+
# @return [String] The enum value
25+
def self.build_from_hash(value)
26+
new.build_from_hash(value)
27+
end
28+
29+
# Builds the enum from string
30+
# @param [String] The enum value in the form of the string
31+
# @return [String] The enum value
32+
def build_from_hash(value)
33+
return value if EventStatus.all_vars.include?(value)
34+
raise "Invalid ENUM value #{value} for class #EventStatus"
35+
end
36+
end
37+
end
38+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 EventType
11+
FETCH = "fetch".freeze
12+
RECORD = "record".freeze
13+
LOG = "log".freeze
14+
TRANSFORM = "transform".freeze
15+
16+
def self.all_vars
17+
@all_vars ||= [FETCH, RECORD, LOG, TRANSFORM].freeze
18+
end
19+
20+
# Builds the enum from string
21+
# @param [String] The enum value in the form of the string
22+
# @return [String] The enum value
23+
def self.build_from_hash(value)
24+
new.build_from_hash(value)
25+
end
26+
27+
# Builds the enum from string
28+
# @param [String] The enum value in the form of the string
29+
# @return [String] The enum value
30+
def build_from_hash(value)
31+
return value if EventType.all_vars.include?(value)
32+
raise "Invalid ENUM value #{value} for class #EventType"
33+
end
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)