-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[C#] Bug with enum classes referenced from other objects #1088
Comments
rubms
pushed a commit
to rubms/openapi-generator
that referenced
this issue
Sep 24, 2018
…on properties while processing objects that reference them. Launched the ./bin/csharp-petstore-all.sh script.
4 tasks
I have filed a pull request that fixes the problem. |
Fixed, as #1089 has been merged into master. Thanks @jimschubert ! |
6 tasks
A-Joshi
pushed a commit
to ihsmarkitoss/openapi-generator
that referenced
this issue
Feb 27, 2019
…renced from other objects (OpenAPITools#1089) * Run ./bin/utils/ensure-up-to-date to re-generate samples run in the CI. * Fixed the OpenAPITools#1088 issue by removing the update of enumeration properties while processing objects that reference them. Launched the ./bin/csharp-petstore-all.sh script.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The C# auto-generated code for enum classes referenced from other objects is generated with errors, so that the auto-generated code does not compile.
The
EnumClass
in the sample below is auto-generated likeThis code does not compile. Instead it should be generated like
openapi-generator version
Reproduced with OpenAPI generator v3.2.3.
OpenAPI declaration file content or url
Command line used for generation
java -jar openapi-generator-cli-3.2.3.jar generate -g csharp -i test_enums.yml -o test_enums
Steps to reproduce
Auto-generate code from the specification above using the openapi-generator-cli-3.2.3, specifying the
csharp
generator. The auto-generated model,EnumClass
, is incorrectly generated and does not compile.Related issues/PRs
#635 is a similar issue, which talks about the same problem. The #774 pull request fixes the problem but it is still reproduced when the enumeration class is referred to from other objects in the specification.
Suggest a fix/enhancement
The code is incorrectly generated from the
enumClass.mustache
template because the enum values (which are of String type) a not correctly marked as strings. ThisisString
property comes tofalse
because of thepostProcessEnumRefs()
method inAbstractCSharpCodegen.java
. That method post-processes enums that are referenced from other classes, and includes a call toupdateCodegenPropertyEnum()
.updateCodegenPropertyEnum()
re-evaluates theisString
condition of the enumeration values:isDataTypeString(dataType)
evaluates as false, becausedataType
in enum references is notString
, but the name of the enum class (EnumClass in this the sample above).I don't see the point in calling
updateCodegenPropertyEnum()
for these referenced enumerations. I suggest removing that call. I have checked and commenting that call fixes the problem, while it breaks no unit tests and the auto-generate samples stay correct.The text was updated successfully, but these errors were encountered: