Skip to content

Commit 74bd854

Browse files
feat(specs): update transformation specs for no-code (generated)
algolia/api-clients-automation#4901 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Mehmet Ali Gok <[email protected]>
1 parent c3f3d1d commit 74bd854

File tree

7 files changed

+614
-7
lines changed

7 files changed

+614
-7
lines changed

lib/algolia/models/ingestion/transformation.rb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ class Transformation
1414
# The authentications associated with the current transformation.
1515
attr_accessor :authentication_ids
1616

17-
# The source code of the transformation.
17+
# It is deprecated. Use the `input` field with proper `type` instead to specify the transformation code.
1818
attr_accessor :code
1919

20+
attr_accessor :type
21+
22+
attr_accessor :input
23+
2024
# The uniquely identified name of your transformation.
2125
attr_accessor :name
2226

@@ -38,6 +42,8 @@ def self.attribute_map
3842
:transformation_id => :transformationID,
3943
:authentication_ids => :authenticationIDs,
4044
:code => :code,
45+
:type => :type,
46+
:input => :input,
4147
:name => :name,
4248
:description => :description,
4349
:owner => :owner,
@@ -52,6 +58,8 @@ def self.types_mapping
5258
:transformation_id => :"String",
5359
:authentication_ids => :"Array<String>",
5460
:code => :"String",
61+
:type => :"TransformationType",
62+
:input => :"TransformationInput",
5563
:name => :"String",
5664
:description => :"String",
5765
:owner => :"String",
@@ -110,6 +118,14 @@ def initialize(attributes = {})
110118
self.code = nil
111119
end
112120

121+
if attributes.key?(:type)
122+
self.type = attributes[:type]
123+
end
124+
125+
if attributes.key?(:input)
126+
self.input = attributes[:input]
127+
end
128+
113129
if attributes.key?(:name)
114130
self.name = attributes[:name]
115131
else
@@ -145,6 +161,8 @@ def ==(other)
145161
transformation_id == other.transformation_id &&
146162
authentication_ids == other.authentication_ids &&
147163
code == other.code &&
164+
type == other.type &&
165+
input == other.input &&
148166
name == other.name &&
149167
description == other.description &&
150168
owner == other.owner &&
@@ -161,7 +179,7 @@ def eql?(other)
161179
# Calculates hash code according to all attributes.
162180
# @return [Integer] Hash code
163181
def hash
164-
[transformation_id, authentication_ids, code, name, description, owner, created_at, updated_at].hash
182+
[transformation_id, authentication_ids, code, type, input, name, description, owner, created_at, updated_at].hash
165183
end
166184

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

lib/algolia/models/ingestion/transformation_create.rb

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ module Algolia
99
module Ingestion
1010
# API request body for creating a transformation.
1111
class TransformationCreate
12-
# The source code of the transformation.
12+
# It is deprecated. Use the `input` field with proper `type` instead to specify the transformation code.
1313
attr_accessor :code
1414

1515
# The uniquely identified name of your transformation.
1616
attr_accessor :name
1717

18+
attr_accessor :type
19+
20+
attr_accessor :input
21+
1822
# A descriptive name for your transformation of what it does.
1923
attr_accessor :description
2024

@@ -26,6 +30,8 @@ def self.attribute_map
2630
{
2731
:code => :code,
2832
:name => :name,
33+
:type => :type,
34+
:input => :input,
2935
:description => :description,
3036
:authentication_ids => :authenticationIDs
3137
}
@@ -36,6 +42,8 @@ def self.types_mapping
3642
{
3743
:code => :"String",
3844
:name => :"String",
45+
:type => :"TransformationType",
46+
:input => :"TransformationInput",
3947
:description => :"String",
4048
:authentication_ids => :"Array<String>"
4149
}
@@ -73,8 +81,6 @@ def initialize(attributes = {})
7381

7482
if attributes.key?(:code)
7583
self.code = attributes[:code]
76-
else
77-
self.code = nil
7884
end
7985

8086
if attributes.key?(:name)
@@ -83,6 +89,18 @@ def initialize(attributes = {})
8389
self.name = nil
8490
end
8591

92+
if attributes.key?(:type)
93+
self.type = attributes[:type]
94+
else
95+
self.type = nil
96+
end
97+
98+
if attributes.key?(:input)
99+
self.input = attributes[:input]
100+
else
101+
self.input = nil
102+
end
103+
86104
if attributes.key?(:description)
87105
self.description = attributes[:description]
88106
end
@@ -101,6 +119,8 @@ def ==(other)
101119
self.class == other.class &&
102120
code == other.code &&
103121
name == other.name &&
122+
type == other.type &&
123+
input == other.input &&
104124
description == other.description &&
105125
authentication_ids == other.authentication_ids
106126
end
@@ -114,7 +134,7 @@ def eql?(other)
114134
# Calculates hash code according to all attributes.
115135
# @return [Integer] Hash code
116136
def hash
117-
[code, name, description, authentication_ids].hash
137+
[code, name, type, input, description, authentication_ids].hash
118138
end
119139

120140
# Builds the object from hash

0 commit comments

Comments
 (0)