-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[BUG][Ruby] Using oneOf generated code has unexpected results #3630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
@ssteeg-mdsol Thank you for the report. [
{
"results": {
// AuthenticationMonitor
"items": [
{
"result": true
}
]
}
},
{
"results": {
// SmokeTestMonitor
"items": [
{
"passed": true
}
]
}
}
] |
And isn't the expected output in your description here?
|
This is not just a problem for Ruby, but for example Python. class MonitorResults(object):
"""NOTE: This class is auto generated by OpenAPI Generator.
Ref: https://openapi-generator.tech
Do not edit the class manually.
"""
"""
Attributes:
openapi_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
openapi_types = {
'items': 'list[SmokeTestMonitorItems]' # <- missing AuthenticationMonitorItems
} This looks like a problem with the Ruby client. |
@autopp Sorry for the slow reply! My Gmail filters let me down 🙇 Thanks for taking a look at this issue! You're right about the expected output, I will update the issue description. I believe the response you provided should reproduce the problem but will double-check this afternoon. |
Confirmed that the response you provided reproduces the issue. A response of [
{
"results": {
// AuthenticationMonitor
"items": [
{
"result": true
}
]
}
},
{
"results": {
// SmokeTestMonitor
"items": [
{
"passed": true
}
]
}
} results in the following (from the ruby console): items[0].results.items
# => [#< ClientExample::SmokeTestResult:0x00007ff1261bb380>]
items[0].results.items.first.passed
# => nil
items[0].results.items.first.result
Traceback (most recent call last):
1: from (irb):11
NoMethodError (undefined method `result` for #< ClientExample::SmokeTestResult:0x00007ff1261bb380>)
Did you mean? rescue
items[1].results.items
# => [#< ClientExample::SmokeTestResult:0x00007f98f4b191f0 @passed=true>]
items[1].results.items.first.passed
# => true |
@autopp Do you have ideas about how or where the logic to handle |
It's a general issue with the generator. Java has the same issue, no fix has been provided so far. |
@ssteeg-mdsol Sorry for the late reply. |
my start was to look into the java generator code, and I found absolutely no support for it in the example generator. i think it is just unimplemented. |
I tried to take a stab at it in #5706 |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report Checklist
Description
When a
oneOf
is used, the generated model only includes one of the possible classes. Using the client, objects for all class types are forced into the same class, even if they're a different class.In the below example, if the API returns a
AuthenticationMonitor
MonitorResult object, the generated client forces it into theSmokeTestMonitor
class type. This is a problem as it's the incorrect class type and as a result the model attributes are allnil
.Current output for the
AuthenticationMonitor
MonitorResult object:Expected output for the
AuthenticationMonitor
MonitorResult object:openapi-generator version
4.1.0, seems to occur in every 4.x version. Haven't checked previous versions.
OpenAPI declaration file content or url
OpenAPI spec
AuthenticationMonitor
andSmokeTestMonitor
are the same but the property name insideitems
is differentCommand line used for generation
openapi-generator generate -i <OPENAPI_SPEC> -g ruby -o <TEMP_DIR> -c <CONFIG_PATH>
Steps to reproduce
Related issues/PRs
Maybe #15 is related, but this issue is more specific to the Ruby client.
Another issue related to
oneOf
for the Ruby client is the generation of objects within aresponse
schema. If you have the following OpenAPI spec, the class type gets generated asExampleClient::OneOfsimpleObjectcomplexObject
, and that class does not exist.OpenAPI spec snippet
Here is the spec:Suggest a fix
In https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache#L49, the generated client only includes one option
Array<SmokeTestResult>
. I'm not sure about a specific fix, but has there been any Ruby-specific development into this area?The text was updated successfully, but these errors were encountered: