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 the SmokeTestMonitor class type. This is a problem as it's the incorrect class type and as a result the model attributes are all nil.
Current output for the AuthenticationMonitor MonitorResult object:
...
@items=[#<ClientExample::SmokeTestResult:0x00007fb45220eaa0>]
...
Expected output for the AuthenticationMonitor MonitorResult object:
...
@items=[#<ClientExample::AuthenticationMonitorItems:0x00007fb45220eaa0 @result=true>]
...
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 and SmokeTestMonitor are the same but the property name inside items is different
openapi: 3.0.2
info:
title: Example
version: v1
paths:
/endpoint:
get:
summary: Get All Monitors
responses:
'200':
description: Successful operation.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Monitor'
components:
schemas:
Monitor:
type: object
properties:
results:
$ref: '#/components/schemas/MonitorResults'
MonitorResults:
oneOf:
- $ref: '#/components/schemas/AuthenticationMonitor'
- $ref: '#/components/schemas/SmokeTestMonitor'
AuthenticationMonitor:
type: object
properties:
items:
type: array
items:
type: object
properties:
result:
type: boolean
SmokeTestMonitor:
type: object
properties:
items:
type: array
description: Collection of smoke test result checks.
items:
type: object
properties:
passed:
type: boolean
Command line used for generation
openapi-generator generate -i <OPENAPI_SPEC> -g ruby -o <TEMP_DIR> -c <CONFIG_PATH>
Steps to reproduce
- Run the command to generate the Ruby client
- Look at the
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 a response schema. If you have the following OpenAPI spec, the class type gets generated as ExampleClient::OneOfsimpleObjectcomplexObject, and that class does not exist.
OpenAPI spec snippet
Here is the spec:
paths:
/endpoint:
get:
summary: Get All Monitors
responses:
'200':
description: Successful operation.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/simpleObject'
- $ref: '#/components/schemas/complexObject'
components:
schemas:
simpleObject:
type: object
properties:
simple_property1:
type: string
complexObject:
type: object
properties:
complex_property1:
type: string
complex_property2:
type: string
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?
Bug Report Checklist
Description
When a
oneOfis 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
AuthenticationMonitorMonitorResult object, the generated client forces it into theSmokeTestMonitorclass 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
AuthenticationMonitorMonitorResult object:Expected output for the
AuthenticationMonitorMonitorResult 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
AuthenticationMonitorandSmokeTestMonitorare the same but the property name insideitemsis 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
oneOffor the Ruby client is the generation of objects within aresponseschema. 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?