Skip to content
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 escaped reserved words have HTML entities not backticks #4537

Closed
dalewking opened this issue Nov 19, 2019 · 5 comments · Fixed by #5221
Closed

[BUG] Kotlin escaped reserved words have HTML entities not backticks #4537

dalewking opened this issue Nov 19, 2019 · 5 comments · Fixed by #5221

Comments

@dalewking
Copy link
Contributor

Description

Note that this is difficult to express without markdown translating what I enter.

Kotlin supports escaping reserved words by surrounding it with backticks as in `data`

I have an API that has a parameter named data that is a reserved word in Kotlin and the generator is recognizing that it is reserved, but when the source file is written the backticks are being turned into HTML character entities.

So instead of seeing `data` in the code what I see is `data`

openapi-generator version

4.2.1

OpenAPI declaration file content or url

Here is the URL of the API I am trying to work with: https://api.youneedabudget.com/papi/spec-v1-swagger.json

Command line used for generation

Gradle.kts declaration I am using:

val swaggerInput = file("ynab-v1-swagger.json")
val swaggerOutputDir = file("build/swagger")

openApiGenerate {
    inputSpec.set(swaggerInput.toString())
    outputDir.set(swaggerOutputDir.toString())
    generatorName.set("kotlin")
    invokerPackage.set("mypackage.ynab.client")
    modelPackage.set("mypackage.ynab.client.model")
    apiPackage.set("mypackage.client.api")
    configOptions.put("dateLibrary", "java8")
}
Steps to reproduce

Generate kotlin code of an API that uses a reserved word

@dalewking
Copy link
Contributor Author

Looks like the solution in my case is to replace all instances of {{paramName}} with {{{paramName}}} in kotlin-client/api.mustache, but that only fixes it for parameter names. Probably needed many other places as well.

@dalewking
Copy link
Contributor Author

From what I read {{&paramName}} is another alternative. For now I have created a gradle step that copies and renames those parameters since they are in endpoints that I am not even using.

@stapel
Copy link
Contributor

stapel commented Jan 11, 2020

Pretty much nothing in kotlin, except maybe comments and KDocs, should be html-encoded, the codegen handles that.

@fleskesvor
Copy link

I'm experiencing the same issue with generated Kotlin with version 4.2.2 of the Gradle plugin.

@jimschubert
Copy link
Member

For those experiencing this in older versions of the generator, you can modify the template and change {{paramName}} to {{{paramName}}} to resolve without upgrade. To change the template, you'd copy the affected template file to some directory retaining the directory structure after kotlin-client.

For example, if you wanted to modify modules/openapi-generator/src/main/resources/kotlin-client/libraries/multiplatform/api.mustache, you would create some directory (e.g. ~/my_templates) and add the file at libraries/multiplatform/api.mustache under that directory (final: ~/my_templates/libraries/multiplatform/api.mustache). Make the adjustment listed above, and generate with the -t option pointing to the base directory (example: -t ~/my_templates).

Full details on customizing the template are at https://openapi-generator.tech/docs/templating.

I'll have this fixed in #5221 and will include the additional fix from @stapel in that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants