Skip to content

Commit 0e9466c

Browse files
feat(specs): add fields for metadata in composition injectedItems (generated)
algolia/api-clients-automation#5241 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Gavin Wade <[email protected]>
1 parent 99d1ead commit 0e9466c

File tree

2 files changed

+223
-4
lines changed

2 files changed

+223
-4
lines changed

lib/algolia/models/composition/hit.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Hit
2222

2323
attr_accessor :_distinct_seq_id
2424

25+
attr_accessor :_extra
26+
2527
attr_accessor :additional_properties
2628

2729
# Attribute mapping from ruby-style variable name to JSON key.
@@ -31,7 +33,8 @@ def self.attribute_map
3133
:_highlight_result => :_highlightResult,
3234
:_snippet_result => :_snippetResult,
3335
:_ranking_info => :_rankingInfo,
34-
:_distinct_seq_id => :_distinctSeqID
36+
:_distinct_seq_id => :_distinctSeqID,
37+
:_extra => :_extra
3538
}
3639
end
3740

@@ -42,7 +45,8 @@ def self.types_mapping
4245
:_highlight_result => :"Hash<String, HighlightResult>",
4346
:_snippet_result => :"Hash<String, SnippetResult>",
4447
:_ranking_info => :"HitRankingInfo",
45-
:_distinct_seq_id => :"Integer"
48+
:_distinct_seq_id => :"Integer",
49+
:_extra => :"HitMetadata"
4650
}
4751
end
4852

@@ -86,6 +90,10 @@ def initialize(attributes = {})
8690
self._distinct_seq_id = attributes[:_distinct_seq_id]
8791
end
8892

93+
if attributes.key?(:_extra)
94+
self._extra = attributes[:_extra]
95+
end
96+
8997
# add extra attribute to additional_properties
9098
self.additional_properties ||= {}
9199
self.additional_properties.merge!(attributes.reject { |k, _| self.class.attribute_map.key?(k.to_sym) })
@@ -100,7 +108,8 @@ def ==(other)
100108
_highlight_result == other._highlight_result &&
101109
_snippet_result == other._snippet_result &&
102110
_ranking_info == other._ranking_info &&
103-
_distinct_seq_id == other._distinct_seq_id
111+
_distinct_seq_id == other._distinct_seq_id &&
112+
_extra == other._extra
104113
end
105114

106115
# @see the `==` method
@@ -112,7 +121,7 @@ def eql?(other)
112121
# Calculates hash code according to all attributes.
113122
# @return [Integer] Hash code
114123
def hash
115-
[algolia_object_id, _highlight_result, _snippet_result, _ranking_info, _distinct_seq_id].hash
124+
[algolia_object_id, _highlight_result, _snippet_result, _ranking_info, _distinct_seq_id, _extra].hash
116125
end
117126

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

0 commit comments

Comments
 (0)