question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dalewkingcommented, Nov 19, 2019

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.

0reactions
jimschubertcommented, Feb 6, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Escape reserved words in an import - kotlin - Stack Overflow
The java interop documentation says you can use backtick (`) character but this doesn't work in imports. So how to escaped reserved words...
Read more >
Disabling auto-escaping in template engines is security ...
When escape occurs, characters that make sense to the browser (eg: <a>) will be transformed/replaced with escaped/sanitized values (eg: & lt;a& gt; )....
Read more >
Class names with backticks containing symbols "*", "?" and ...
A small investigation after KT-17422 showed that class names with backticks containing symbols "*", "?" fail on compilation to target JVM in Windows...
Read more >
Introduction - Kotlin language specification
Kotlin supports escaping identifiers by enclosing any sequence of characters into backtick ( ` ) characters, allowing to use any name as an...
Read more >
[Solved]-Unsolvable MySQL error? - appsloveworld
Edit: And as others have stated; you are using reserved words. ... and REPEAT are reserved keywords in MySQL so you have to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found