Skip to content

Commit 7656747

Browse files
committed
fix(crystal): return early if value is nil
1 parent 594c604 commit 7656747

9 files changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
# @param [Object] value Any valid value
2626
# @return [Hash] Returns the value in the form of hash
2727
private def _to_h(value)
28+
return nil if value.nil?
29+
2830
if value.is_a?(Hash)
2931
hash = NetboxClient::RecursiveHash.new
3032
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ module Petstore
9595
# @param [Object] value Any valid value
9696
# @return [Hash] Returns the value in the form of hash
9797
private def _to_h(value)
98+
return nil if value.nil?
99+
98100
if value.is_a?(Hash)
99101
hash = NetboxClient::RecursiveHash.new
100102
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ module Petstore
9191
# @param [Object] value Any valid value
9292
# @return [Hash] Returns the value in the form of hash
9393
private def _to_h(value)
94+
return nil if value.nil?
95+
9496
if value.is_a?(Hash)
9597
hash = NetboxClient::RecursiveHash.new
9698
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ module Petstore
103103
# @param [Object] value Any valid value
104104
# @return [Hash] Returns the value in the form of hash
105105
private def _to_h(value)
106+
return nil if value.nil?
107+
106108
if value.is_a?(Hash)
107109
hash = NetboxClient::RecursiveHash.new
108110
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ module Petstore
353353
# @param [Object] value Any valid value
354354
# @return [Hash] Returns the value in the form of hash
355355
private def _to_h(value)
356+
return nil if value.nil?
357+
356358
if value.is_a?(Hash)
357359
hash = NetboxClient::RecursiveHash.new
358360
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ module Petstore
161161
# @param [Object] value Any valid value
162162
# @return [Hash] Returns the value in the form of hash
163163
private def _to_h(value)
164+
return nil if value.nil?
165+
164166
if value.is_a?(Hash)
165167
hash = NetboxClient::RecursiveHash.new
166168
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ module Petstore
162162
# @param [Object] value Any valid value
163163
# @return [Hash] Returns the value in the form of hash
164164
private def _to_h(value)
165+
return nil if value.nil?
166+
165167
if value.is_a?(Hash)
166168
hash = NetboxClient::RecursiveHash.new
167169
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ module Petstore
8686
# @param [Object] value Any valid value
8787
# @return [Hash] Returns the value in the form of hash
8888
private def _to_h(value)
89+
return nil if value.nil?
90+
8991
if value.is_a?(Hash)
9092
hash = NetboxClient::RecursiveHash.new
9193
value.each { |k, v| hash[k] = _to_h(v) }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ module Petstore
117117
# @param [Object] value Any valid value
118118
# @return [Hash] Returns the value in the form of hash
119119
private def _to_h(value)
120+
return nil if value.nil?
121+
120122
if value.is_a?(Hash)
121123
hash = NetboxClient::RecursiveHash.new
122124
value.each { |k, v| hash[k] = _to_h(v) }

0 commit comments

Comments
 (0)