-
Notifications
You must be signed in to change notification settings - Fork 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
Model enums are broken in generated C# client code #8027
Comments
Building 'swagger-codegen' locally, i have found a makeshift solution for this problem (that obviously requires further testing). with This works for the petstore/v2-demo, but needs to be looked into by someone with more experience. i don't think there is any DataType that cannot be masked with double quotes. |
I also have this problem. Please fix is ASAP. BTW, I found that the enum types are correct when download a generated client via the SwaggerHub(https://app.swaggerhub.com) online, but using 'swagger-codegen' 2.3.1 locally produces incorrect code. So the problem must be fixed officially already. Please help. |
Depending on HashMap iteration order, the isString flag added to string enum values can be lost due to copying a reference to the allowableValues map to properties that reference the enum. The result is that the code fails to compile. This should fix swagger-api#7656, fix swagger-api#7657 (regarded as a duplicate of 7656), and fix swagger-api#8027 (which also appears to be the same issue).
Depending on HashMap iteration order, the isString flag added to string enum values can be lost due to copying a reference to the allowableValues map to properties that reference the enum. The result is that the code fails to compile. This should fix swagger-api#7656, fix swagger-api#7657 (regarded as a duplicate of 7656), and fix swagger-api#8027 (which also appears to be the same issue).
Same problem in version 3.0.14, installed from Homebrew. |
should be fixed in #9936 (and swagger-api/swagger-codegen-generators#561 for 3.0.0) |
Description
(This issue my be related to #7947.)
I have tried to generate a C# client solution using the codegen-cli 2.3.1.
The specification in question can be found at: https://api.apis.guru/v2/specs/amazonaws.com/AWSMigrationHub/2017-05-31/swagger.json
This functions fine with 2.2.3, and generates a solution that can be built in VS2013. However, using 2.3.1, the solution cannot be built as the C# code in one of the model classes (Status.cs) is invalid. A snippet of the class is shown below which illustrates the problem:
Status.cs:34 (generated using 2.2.3) - this works as expected:
Status.cs:34 (generated using 2.3.1) - this generates invalid C#:
If I generate using 2.3.1, but specify a folder containing the modelEnum.mustache template from 2.2.3, the following is generated, which is still invalid:
(where the quotes around NOT_STARTED have not been planted.)
As of 16/04/18, the issue is still unfixed in the 2.4 snapshot.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
https://api.apis.guru/v2/specs/amazonaws.com/AWSMigrationHub/2017-05-31/swagger.json
Command line used for generation
java -jar swagger-codegen-cli-2.3.1.jar generate -i aws_swagger.json -l csharp -DapiTests=false -DmodelTests=false
(where aws_swagger.json is a local copy of the version linked above.)
Steps to reproduce
Run the above command for the specification linked above (AWS Migration Hub).
Related issues/PRs
#7947
Suggest a fix/enhancement
In the spec, the Status enum is defined as follows:
By placing dummy text in isString tags in the modelEnum.mustache template (e.g. {{#isString}}This is a string{{/isString}}), it becomes apparent that the type tag for this variable is not being set correctly (to string), as the dummy text is not planted in the generated code.
The text was updated successfully, but these errors were encountered: