Skip to content

Commit c54d72a

Browse files
committed
fix(crystal): update samples
1 parent 4f71fb0 commit c54d72a

File tree

9 files changed

+8
-579
lines changed

9 files changed

+8
-579
lines changed

samples/client/petstore/crystal/shard.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
name: petstore
2+
23
version: 1.0.0
4+
35
authors:
46
-
7+
58
description: |
69
-
10+
711
crystal: ">= 0.35.1"
12+
813
dependencies:
914
any_hash:
1015
github: Sija/any_hash.cr
@@ -13,11 +18,11 @@ dependencies:
1318
version: ~> 1.3.13
1419

1520
development_dependencies:
16-
kemal:
17-
github: kemalcr/kemal
18-
version: ~>1.5.0
1921
ameba:
2022
github: crystal-ameba/ameba
23+
kemal:
24+
github: kemalcr/kemal
25+
version: ~> 1.5.0
2126
spectator:
2227
gitlab: arctic-fox/spectator
2328
version: ~> 0.12.0

samples/client/petstore/crystal/src/petstore/models/another_property_name_mapping.cr

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -72,78 +72,6 @@ module Petstore
7272
[http_debug_operation, underscore_type, _type, type_with_underscore].hash
7373
end
7474

75-
# Builds the object from hash
76-
# @param [Hash] attributes Model attributes in the form of hash
77-
# @return [Object] Returns the model itself
78-
def self.build_from_hash(attributes)
79-
new.build_from_hash(attributes)
80-
end
81-
82-
# Builds the object from hash
83-
# @param [Hash] attributes Model attributes in the form of hash
84-
# @return [Object] Returns the model itself
85-
def build_from_hash(attributes)
86-
return nil unless attributes.is_a?(Hash)
87-
self.class.openapi_types.each_pair do |key, type|
88-
if !attributes[self.class.attribute_map[key]]? && self.class.openapi_nullable.includes?(key)
89-
self.send("#{key}=", nil)
90-
elsif type =~ /\AArray<(.*)>/i
91-
# check to ensure the input is an array given that the attribute
92-
# is documented as an array but the input is not
93-
if attributes[self.class.attribute_map[key]].is_a?(Array)
94-
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
95-
end
96-
elsif !attributes[self.class.attribute_map[key]].nil?
97-
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
98-
end
99-
end
100-
101-
self
102-
end
103-
104-
# Deserializes the data based on type
105-
# @param string type Data type
106-
# @param string value Value to be deserialized
107-
# @return [Object] Deserialized data
108-
def _deserialize(type, value)
109-
case type.to_sym
110-
when :Time
111-
Time.parse(value)
112-
when :Date
113-
Date.parse(value)
114-
when :String
115-
value.to_s
116-
when :Integer
117-
value.to_i
118-
when :Float
119-
value.to_f
120-
when :Boolean
121-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
122-
true
123-
else
124-
false
125-
end
126-
when :Object
127-
# generic object (usually a Hash), return directly
128-
value
129-
when /\AArray<(?<inner_type>.+)>\z/
130-
inner_type = Regexp.last_match[:inner_type]
131-
value.map { |v| _deserialize(inner_type, v) }
132-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
133-
k_type = Regexp.last_match[:k_type]
134-
v_type = Regexp.last_match[:v_type]
135-
({} of Symbol => String).tap do |hash|
136-
value.each do |k, v|
137-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
138-
end
139-
end
140-
else # model
141-
# models (e.g. Pet) or oneOf
142-
klass = Petstore.const_get(type)
143-
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
144-
end
145-
end
146-
14775
# Returns the string representation of the object
14876
# @return [String] String presentation of the object
14977
def to_s

samples/client/petstore/crystal/src/petstore/models/api_response.cr

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -69,78 +69,6 @@ module Petstore
6969
[code, _type, message].hash
7070
end
7171

72-
# Builds the object from hash
73-
# @param [Hash] attributes Model attributes in the form of hash
74-
# @return [Object] Returns the model itself
75-
def self.build_from_hash(attributes)
76-
new.build_from_hash(attributes)
77-
end
78-
79-
# Builds the object from hash
80-
# @param [Hash] attributes Model attributes in the form of hash
81-
# @return [Object] Returns the model itself
82-
def build_from_hash(attributes)
83-
return nil unless attributes.is_a?(Hash)
84-
self.class.openapi_types.each_pair do |key, type|
85-
if !attributes[self.class.attribute_map[key]]? && self.class.openapi_nullable.includes?(key)
86-
self.send("#{key}=", 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[self.class.attribute_map[key]].is_a?(Array)
91-
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
92-
end
93-
elsif !attributes[self.class.attribute_map[key]].nil?
94-
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
95-
end
96-
end
97-
98-
self
99-
end
100-
101-
# Deserializes the data based on type
102-
# @param string type Data type
103-
# @param string value Value to be deserialized
104-
# @return [Object] Deserialized data
105-
def _deserialize(type, value)
106-
case type.to_sym
107-
when :Time
108-
Time.parse(value)
109-
when :Date
110-
Date.parse(value)
111-
when :String
112-
value.to_s
113-
when :Integer
114-
value.to_i
115-
when :Float
116-
value.to_f
117-
when :Boolean
118-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
119-
true
120-
else
121-
false
122-
end
123-
when :Object
124-
# generic object (usually a Hash), return directly
125-
value
126-
when /\AArray<(?<inner_type>.+)>\z/
127-
inner_type = Regexp.last_match[:inner_type]
128-
value.map { |v| _deserialize(inner_type, v) }
129-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
130-
k_type = Regexp.last_match[:k_type]
131-
v_type = Regexp.last_match[:v_type]
132-
({} of Symbol => String).tap do |hash|
133-
value.each do |k, v|
134-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
135-
end
136-
end
137-
else # model
138-
# models (e.g. Pet) or oneOf
139-
klass = Petstore.const_get(type)
140-
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
141-
end
142-
end
143-
14472
# Returns the string representation of the object
14573
# @return [String] String presentation of the object
14674
def to_s

samples/client/petstore/crystal/src/petstore/models/category.cr

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -82,78 +82,6 @@ module Petstore
8282
[id, name].hash
8383
end
8484

85-
# Builds the object from hash
86-
# @param [Hash] attributes Model attributes in the form of hash
87-
# @return [Object] Returns the model itself
88-
def self.build_from_hash(attributes)
89-
new.build_from_hash(attributes)
90-
end
91-
92-
# Builds the object from hash
93-
# @param [Hash] attributes Model attributes in the form of hash
94-
# @return [Object] Returns the model itself
95-
def build_from_hash(attributes)
96-
return nil unless attributes.is_a?(Hash)
97-
self.class.openapi_types.each_pair do |key, type|
98-
if !attributes[self.class.attribute_map[key]]? && self.class.openapi_nullable.includes?(key)
99-
self.send("#{key}=", nil)
100-
elsif type =~ /\AArray<(.*)>/i
101-
# check to ensure the input is an array given that the attribute
102-
# is documented as an array but the input is not
103-
if attributes[self.class.attribute_map[key]].is_a?(Array)
104-
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
105-
end
106-
elsif !attributes[self.class.attribute_map[key]].nil?
107-
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
108-
end
109-
end
110-
111-
self
112-
end
113-
114-
# Deserializes the data based on type
115-
# @param string type Data type
116-
# @param string value Value to be deserialized
117-
# @return [Object] Deserialized data
118-
def _deserialize(type, value)
119-
case type.to_sym
120-
when :Time
121-
Time.parse(value)
122-
when :Date
123-
Date.parse(value)
124-
when :String
125-
value.to_s
126-
when :Integer
127-
value.to_i
128-
when :Float
129-
value.to_f
130-
when :Boolean
131-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
132-
true
133-
else
134-
false
135-
end
136-
when :Object
137-
# generic object (usually a Hash), return directly
138-
value
139-
when /\AArray<(?<inner_type>.+)>\z/
140-
inner_type = Regexp.last_match[:inner_type]
141-
value.map { |v| _deserialize(inner_type, v) }
142-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
143-
k_type = Regexp.last_match[:k_type]
144-
v_type = Regexp.last_match[:v_type]
145-
({} of Symbol => String).tap do |hash|
146-
value.each do |k, v|
147-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
148-
end
149-
end
150-
else # model
151-
# models (e.g. Pet) or oneOf
152-
klass = Petstore.const_get(type)
153-
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
154-
end
155-
end
156-
15785
# Returns the string representation of the object
15886
# @return [String] String presentation of the object
15987
def to_s

samples/client/petstore/crystal/src/petstore/models/format_test.cr

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -318,78 +318,6 @@ module Petstore
318318
[integer, int32, int64, number, float, double, decimal, string, byte, binary, date, date_time, uuid, password, pattern_with_digits, pattern_with_digits_and_delimiter].hash
319319
end
320320

321-
# Builds the object from hash
322-
# @param [Hash] attributes Model attributes in the form of hash
323-
# @return [Object] Returns the model itself
324-
def self.build_from_hash(attributes)
325-
new.build_from_hash(attributes)
326-
end
327-
328-
# Builds the object from hash
329-
# @param [Hash] attributes Model attributes in the form of hash
330-
# @return [Object] Returns the model itself
331-
def build_from_hash(attributes)
332-
return nil unless attributes.is_a?(Hash)
333-
self.class.openapi_types.each_pair do |key, type|
334-
if !attributes[self.class.attribute_map[key]]? && self.class.openapi_nullable.includes?(key)
335-
self.send("#{key}=", nil)
336-
elsif type =~ /\AArray<(.*)>/i
337-
# check to ensure the input is an array given that the attribute
338-
# is documented as an array but the input is not
339-
if attributes[self.class.attribute_map[key]].is_a?(Array)
340-
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
341-
end
342-
elsif !attributes[self.class.attribute_map[key]].nil?
343-
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
344-
end
345-
end
346-
347-
self
348-
end
349-
350-
# Deserializes the data based on type
351-
# @param string type Data type
352-
# @param string value Value to be deserialized
353-
# @return [Object] Deserialized data
354-
def _deserialize(type, value)
355-
case type.to_sym
356-
when :Time
357-
Time.parse(value)
358-
when :Date
359-
Date.parse(value)
360-
when :String
361-
value.to_s
362-
when :Integer
363-
value.to_i
364-
when :Float
365-
value.to_f
366-
when :Boolean
367-
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
368-
true
369-
else
370-
false
371-
end
372-
when :Object
373-
# generic object (usually a Hash), return directly
374-
value
375-
when /\AArray<(?<inner_type>.+)>\z/
376-
inner_type = Regexp.last_match[:inner_type]
377-
value.map { |v| _deserialize(inner_type, v) }
378-
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
379-
k_type = Regexp.last_match[:k_type]
380-
v_type = Regexp.last_match[:v_type]
381-
({} of Symbol => String).tap do |hash|
382-
value.each do |k, v|
383-
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
384-
end
385-
end
386-
else # model
387-
# models (e.g. Pet) or oneOf
388-
klass = Petstore.const_get(type)
389-
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
390-
end
391-
end
392-
393321
# Returns the string representation of the object
394322
# @return [String] String presentation of the object
395323
def to_s

0 commit comments

Comments
 (0)