-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[KOTLIN][SPRING] fix - properly escape dollar and double quotes #22449
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
base: master
Are you sure you want to change the base?
[KOTLIN][SPRING] fix - properly escape dollar and double quotes #22449
Conversation
…so test for the dollar issue
| ) | ||
| @RequestMapping( | ||
| method = [RequestMethod.GET], | ||
| value = [PATH_ITEMS_ITEM_ID_SOMETHING_ITEM_SUB_ID_GET /* "/items/{item$Id}/something/{item$SubId}" */], |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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""", |
There was a problem hiding this comment.
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...
| /** | ||
| * 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 | ||
| */ |
There was a problem hiding this comment.
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.
| /** | ||
| * 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 |
There was a problem hiding this comment.
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.
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):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
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)