Skip to content

Conversation

@Picazsoo
Copy link
Contributor

@Picazsoo Picazsoo commented Nov 26, 2025

This PR fixes many identified issues with improper escaping of dollar symbol in open api spec. In kotlin, $ has a special meaning in strings and thus needs to be properly escaped by prepending it with backslash \$. In multi-line kotlin strings, the escaping is done by transforming $ into ${'$'}. This merge request fixes the issue everywhere to make compilation possible.

I also unified look and setup of kotlin spring tests where possible. I removed a lot of code repetition and although I am still not super happy with it, the unified structure should make future refactoring a bit easier I presume.

I also checked and fixed any places I could identify where a duplicate escaping of special chars occurred or was simply not needed in the first place.

I fixed all of these (and their {{{.}}} variants):

{{{defaultValue}}}
{{{baseName}}}
{{{path}}}
{{{description}}}
{{{summary}}}
{{{notes}}}
{{{message}}}

I partially covered the fixes by unit tests and partially by introducing new generated samples (and adding the to the compile check pipeline) and by adjusting existing samples to include the potentially problematic strings (param names, descriptions, default values, etc)

For code review of the changed kotlin spring tests I strongly encourage the github setting of ignoring whitespace differences.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. - Tagging: @karismann, @Zomzog, @andrewemery, @4brunu, @yutaka0m, @stefankoppier, @e5l

@Picazsoo Picazsoo changed the title [KOTLIN] fix - properly escape dollar [KOTLIN][SPRING] fix - properly escape dollar and double quotes Nov 27, 2025
)
@RequestMapping(
method = [RequestMethod.GET],
value = [PATH_ITEMS_ITEM_ID_SOMETHING_ITEM_SUB_ID_GET /* "/items/{item$Id}/something/{item$SubId}" */],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not escaped here as it is a comment


companion object {
//for your own safety never directly reuse these path definitions in tests
const val PATH_ITEMS_ITEM_ID_SOMETHING_ITEM_SUB_ID_GET: String = "/items/{item\$Id}/something/{item\$SubId}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

escaped here as it is a string



@ApiOperation(
value = "SQ = \"; SBS = \\; DBS = \\\\; SD = \$some",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQ = single quotes; SBS = single backslash; DBS = double backslash; SD = single dollar with additional text.

tags = ["default",],
summary = "SQ = \"; SBS = \\; DBS = \\\\; SD = \$some",
operationId = "itemsItemIdSomethingItemSubIdGet",
description = """SQ = "; SBS = \; DBS = \\; SD = ${'$'}some""",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This trick is used to escape the dollar in kotlin multiline string. ${'$'}some renders as $some.

I think Kotlin 2.2 has some better way to manage this, but this seems fine for the very improbable edge case anyway. Better than not compiling...

@Picazsoo Picazsoo marked this pull request as ready for review November 27, 2025 16:35
@Picazsoo Picazsoo marked this pull request as draft November 27, 2025 16:35
Comment on lines +8 to +22
/**
* GET /items/{item$Id}/something/{item$SubId} : SQ = "; SBS = \; DBS = \\; SD = $some
* SQ = "; SBS = \; DBS = \\; SD = $some
*
* @param itemDollarId SQ = "; SBS = \; DBS = \\; SD = $some (required)
* @param itemDollarSubId SQ = "; SBS = \; DBS = \\; SD = $some (required)
* @param filterDollarType SQ = "; SBS = \; DBS = \\; SD = $some (optional, default to "SQ = \"; SBS = \\; DBS = \\\\; SD = \$some")
* @param filterDollarSubType SQ = "; SBS = \; DBS = \\; SD = $some (optional, default to "SQ = \"; SBS = \\; DBS = \\\\; SD = \$some")
* @param xCustomHeader SQ = "; SBS = \; DBS = \\; SD = $some (optional)
* @param xCustomHeaderTwo SQ = "; SBS = \; DBS = \\; SD = $some (optional)
* @param sessionDollarToken SQ = "; SBS = \; DBS = \\; SD = $some (optional)
* @param sessionDollarTokenTwo SQ = "; SBS = \; DBS = \\; SD = $some (optional)
* @return SQ = "; SBS = \; DBS = \\; SD = $some (status code 200)
* @see ItemsApi#itemsItemIdSomethingItemSubIdGet
*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stuff here generally does not need escaping - hence not escaped (with the exception of the default string value - there I am escaping it to look identical to the actual string.

@Picazsoo Picazsoo marked this pull request as ready for review November 28, 2025 15:17
Comment on lines +1 to +5
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) ({{{generatorVersion}}}).
* https://openapi-generator.tech
* Do not edit the class manually.
*/ No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will either revert this change or (which I think would be better) will include it in all generated classes above package declaration as a mustache partial.

@Picazsoo Picazsoo marked this pull request as draft December 1, 2025 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant