You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Uncompilable java client source code is produced when an object has a property needing discrimination on a property where the allowable values are enumerated as its own children. This type of pattern, without the enumeration, is seen in the specification itself at the end of the discriminator section. When the allowable values of the discriminated property are an enum, the generated code of each subclass contains an uncompilable constructor like this, where petType is an enum and #getSimpleName() returns a String:
This is a further refinement of the bug definition reported here, with the difference being the context of the problem only apparent in certain types of parent objects: #16073
openapi-generator version
7.0.0-beta -- problem also in 6.6.0, and 6.5.0. Did not test before those.
I used the CLI generator and the maven generator with the same result.
Steps to reproduce
Generate Java client with above spec
Note uncompilable code at client/model/Lizard.java and its siblings, it will have a constructor like this, where petType is an enum but getSimpleName() returns String:
The code used is this example from the Open API spec itself with one line added. The line that is added to the example to break compilation is line 35 in the gist below, to wit:enum: [ Cat, Dog, Lizard ]
I describe a workaround in the related issue above, though it requires introducing a parent response object or similar. Note that this shows that a discriminator can accept an enum as a discriminated property, so long as the parent object does not contain the discriminator.
10959 <- This open PR appears to propose a fix for the issue in Java 14533 <- This open PR appears to propose a fix for the same issue in C#
I would suggest testing the above changes against the problem and using those as a basis for a fix, or using them explicitly if they do fix them problem.
The text was updated successfully, but these errors were encountered:
I've just noticed that the problem can be worked around by changing the default serialization library away from okhttp-gson. So one workaround fix, in a maven project, this would look like...
Bug Report Checklist
Description
Uncompilable java client source code is produced when an object has a property needing discrimination on a property where the allowable values are enumerated as its own children. This type of pattern, without the enumeration, is seen in the specification itself at the end of the discriminator section. When the allowable values of the discriminated property are an enum, the generated code of each subclass contains an uncompilable constructor like this, where petType is an enum and #getSimpleName() returns a String:
This is a further refinement of the bug definition reported here, with the difference being the context of the problem only apparent in certain types of parent objects:
#16073
openapi-generator version
7.0.0-beta -- problem also in 6.6.0, and 6.5.0. Did not test before those.
OpenAPI declaration file content or url
Gist
Generation Details
I used the CLI generator and the maven generator with the same result.
Steps to reproduce
The code used is this example from the Open API spec itself with one line added. The line that is added to the example to break compilation is line 35 in the gist below, to wit:
enum: [ Cat, Dog, Lizard ]
Related issues/PRs
16073
10441
Suggest a fix
I describe a workaround in the related issue above, though it requires introducing a parent response object or similar. Note that this shows that a discriminator can accept an enum as a discriminated property, so long as the parent object does not contain the discriminator.
10959 <- This open PR appears to propose a fix for the issue in Java
14533 <- This open PR appears to propose a fix for the same issue in C#
I would suggest testing the above changes against the problem and using those as a basis for a fix, or using them explicitly if they do fix them problem.
The text was updated successfully, but these errors were encountered: