Skip to content

Commit 840f769

Browse files
committed
fix(crystal): remove non-working code
It's not working because it uses #send method which doesn't exist in Crystal See: https://crystal-lang.org/reference/1.18/crystal_for_rubyists/metaprogramming_help.html#differences-between-ruby-and-crystal
1 parent ab689e0 commit 840f769

1 file changed

Lines changed: 0 additions & 75 deletions

File tree

modules/openapi-generator/src/main/resources/crystal/base_object.mustache

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,3 @@
1-
# Builds the object from hash
2-
# @param [Hash] attributes Model attributes in the form of hash
3-
# @return [Object] Returns the model itself
4-
def self.build_from_hash(attributes)
5-
new.build_from_hash(attributes)
6-
end
7-
8-
# Builds the object from hash
9-
# @param [Hash] attributes Model attributes in the form of hash
10-
# @return [Object] Returns the model itself
11-
def build_from_hash(attributes)
12-
return nil unless attributes.is_a?(Hash)
13-
{{#parent}}
14-
super(attributes)
15-
{{/parent}}
16-
self.class.openapi_types.each_pair do |key, type|
17-
if !attributes[self.class.attribute_map[key]]? && self.class.openapi_nullable.includes?(key)
18-
self.send("#{key}=", nil)
19-
elsif type =~ /\AArray<(.*)>/i
20-
# check to ensure the input is an array given that the attribute
21-
# is documented as an array but the input is not
22-
if attributes[self.class.attribute_map[key]].is_a?(Array)
23-
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
24-
end
25-
elsif !attributes[self.class.attribute_map[key]].nil?
26-
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
27-
end
28-
end
29-
30-
self
31-
end
32-
33-
# Deserializes the data based on type
34-
# @param string type Data type
35-
# @param string value Value to be deserialized
36-
# @return [Object] Deserialized data
37-
def _deserialize(type, value)
38-
case type.to_sym
39-
when :Time
40-
Time.parse(value)
41-
when :Date
42-
Date.parse(value)
43-
when :String
44-
value.to_s
45-
when :Integer
46-
value.to_i
47-
when :Float
48-
value.to_f
49-
when :Boolean
50-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
51-
true
52-
else
53-
false
54-
end
55-
when :Object
56-
# generic object (usually a Hash), return directly
57-
value
58-
when /\AArray<(?<inner_type>.+)>\z/
59-
inner_type = Regexp.last_match[:inner_type]
60-
value.map { |v| _deserialize(inner_type, v) }
61-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
62-
k_type = Regexp.last_match[:k_type]
63-
v_type = Regexp.last_match[:v_type]
64-
({} of Symbol => String).tap do |hash|
65-
value.each do |k, v|
66-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
67-
end
68-
end
69-
else # model
70-
# models (e.g. Pet) or oneOf
71-
klass = {{moduleName}}.const_get(type)
72-
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
73-
end
74-
end
75-
761
# Returns the string representation of the object
772
# @return [String] String presentation of the object
783
def to_s

0 commit comments

Comments
 (0)