-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
[BUG][KOTLIN] Kotlin client generation with generateOneOfAnyOfWrappers=true produces Java code in .kt file that does not compile in a Kotlin project #18890
Comments
@martinLeht thank for reporting the issue. I've filed #18891 to fix it |
Thanks! |
PR merged. Please give it a try with the latest master. (snapshot version available in the project's readme) |
@wing328 Nice, it seems to be working regarding the problems I mentioned earlier, thanks! I noticed tho another problem (possibly related to encoding on generation?). In the template kotlin-client/data_class.mustache we have the following jsonArray variable declaration and for-loop:
The above template produces uncompilable code, when the variable {{name}} = "data" in the OpenAPI spec. The generated code would look like this (uncompilable):
But when the {{name}} = "entities" or something else than "data", it generates code that is compilable and good:
Should I make a separate issue with more details or is this enough? |
Bug Report Checklist
Description
I tested the latest openapi-generator latest (7.7.0-SNAPSHOT) that contains a fix related to better oneOf support for generated Kotlin client code generation. The latest Kotlin client generator generates code that does not compile in a Kotlin project when using new config-option generateOneOfAnyOfWrappers=true. Kotlin generator produces Java code among the Kotlin code which results in a .kt file that does not compile. This problem persists when generation is performed against an OpenAPI schema that uses oneOf and discriminator for polymorphism.
By simply looking at the mustache template files, one can see that there are variables declared in Java syntax and that some exceptions are thrown with "new" keyword that does not exist in Kotlin and thus does not compile. Below are some snippets and references to the templates:
openapi-generator version
This issue currently on latest 7.7.0-SNAPSHOT version.
OpenAPI declaration file content or url
Generation Details
Use latest generator CLI via docker: openapitools/openapi-generator-cli:latest
Use above provided OpenAPI YAML to reproduce (see detailed below).
Configuration options (additional-properties) for Kotlin client generation:
Steps to reproduce
Run kotlin client generation command with latest openapi-generator-cli image against the OpenAPI YAML provided above with above additional properties described above:
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:latest generate -i /local/pets.yaml -g kotlin -o /local/generated/kotlin --additional-properties=generateOneOfAnyOfWrappers=true,enumPropertyNaming=original,serializationLibrary=gson
Related issues/PRs
Bug was a result of PR: 353320c
Suggest a fix
Kotlin mustache templates should be fixed, so that there is only Kotlin syntax and no Java specific syntax. The above listed variable declarations and exception throwing should probably be fixed to Kotlin equivalent as follows:
The text was updated successfully, but these errors were encountered: