Skip to content

Commit 5ad2f84

Browse files
authored
[Ruby] Fixes anyOf Support in Responses (#22392)
* [Ruby] Fixes anyOf Support in Responses * re-gen samples * Revert "re-gen samples" This reverts commit 1b4d85d.
1 parent 74be550 commit 5ad2f84

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

modules/openapi-generator/src/main/resources/ruby-client/api_client.mustache

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,13 @@ module {{moduleName}}
135135
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
136136
end
137137
else
138-
# models (e.g. Pet) or oneOf
138+
# models (e.g. Pet) or oneOf/anyOf
139139
klass = {{moduleName}}.const_get(return_type)
140-
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
140+
if klass.respond_to?(:openapi_one_of) || klass.respond_to?(:openapi_any_of)
141+
klass.build(data)
142+
else
143+
klass.build_from_hash(data)
144+
end
141145
end
142146
end
143147

samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,13 @@ def convert_to_type(data, return_type)
322322
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
323323
end
324324
else
325-
# models (e.g. Pet) or oneOf
325+
# models (e.g. Pet) or oneOf/anyOf
326326
klass = Petstore.const_get(return_type)
327-
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
327+
if klass.respond_to?(:openapi_one_of) || klass.respond_to?(:openapi_any_of)
328+
klass.build(data)
329+
else
330+
klass.build_from_hash(data)
331+
end
328332
end
329333
end
330334

samples/client/petstore/ruby-httpx/lib/petstore/api_client.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,13 @@ def convert_to_type(data, return_type)
255255
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
256256
end
257257
else
258-
# models (e.g. Pet) or oneOf
258+
# models (e.g. Pet) or oneOf/anyOf
259259
klass = Petstore.const_get(return_type)
260-
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
260+
if klass.respond_to?(:openapi_one_of) || klass.respond_to?(:openapi_any_of)
261+
klass.build(data)
262+
else
263+
klass.build_from_hash(data)
264+
end
261265
end
262266
end
263267

samples/client/petstore/ruby/lib/petstore/api_client.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,13 @@ def convert_to_type(data, return_type)
278278
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
279279
end
280280
else
281-
# models (e.g. Pet) or oneOf
281+
# models (e.g. Pet) or oneOf/anyOf
282282
klass = Petstore.const_get(return_type)
283-
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
283+
if klass.respond_to?(:openapi_one_of) || klass.respond_to?(:openapi_any_of)
284+
klass.build(data)
285+
else
286+
klass.build_from_hash(data)
287+
end
284288
end
285289
end
286290

0 commit comments

Comments
 (0)