-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[typescript] fix: escaped multiline comments; implementation option 1 #19528
base: master
Are you sure you want to change the base?
[typescript] fix: escaped multiline comments; implementation option 1 #19528
Conversation
Java
-escaped multiline comments@@ -39,7 +39,7 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory { | |||
* {{&summary}} | |||
{{/summary}} | |||
{{#allParams}} | |||
* @param {{paramName}} {{description}} | |||
* @param {{paramName}} {{{description}}} |
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 noticed here, that we HTML-escape the description. We don't anywhere else, so I fixed this on the way, but it is only tangentially related to the pull request. Please let me know if you'd like to revert this. There are currently no sample fixtures which are covering this codepath.
@@ -6,23 +6,23 @@ import { {{classname}} } from '{{filename}}{{importFileExtension}}'; | |||
{{/tsImports}} |
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 file contains one half of the meaningful changes of this PR.
public void multilineCommentsAreEscaped() { | ||
final DefaultCodegen codegen = new TypeScriptClientCodegen(); | ||
final String multilineComment = "/* This is a multiline comment */"; | ||
final String escapedComment = codegen.escapeUnsafeCharacters(multilineComment); |
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.
noticed escapeUnsafeCharacters
was untested.
public void testEscapeUnsafeCharactersNullGuard() { | ||
final DefaultCodegen codegen = new DefaultCodegen(); | ||
|
||
// allow null |
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 asserts that the type guard exists in the newly introduced function.
@@ -1167,6 +1167,19 @@ public String escapeUnsafeCharacters(String input) { | |||
return input; |
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 file contains one half of the meaningful changes of this PR.
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.
thanks for your contribution!
@@ -100,6 +100,8 @@ public interface CodegenConfig { | |||
|
|||
String escapeUnsafeCharacters(String input); | |||
|
|||
String escapeUnsafeCharactersNullGuard(String input); |
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 chose this name as that is what it currently does. Most implementations of escapeUnsafeCharacters
are not actually about unsafe characters but about multiline comments, so we'd have the chance to name this escapeMultilineComment
if we wanted, which would be more obvious, but has the caveat that the function it calls out to (escapeUnsafeCharacters
) might not be aligned, so I left it with this slightly awkward suffix.
@@ -19,7 +19,8 @@ export class Capitalization { | |||
'capitalSnake'?: string; | |||
'sCAETHFlowPoints'?: string; | |||
/** | |||
* Name of the pet | |||
* Name of the pet | |||
|
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 didn't add trimming to the escapeUnsafeCharacters
implementation. escapeText
has it, hence why this now has an additional newline. Let me know if you prefer trimming leading and trailing whitespace for this and if yes, whether you prefer it for the Typescript generator in specific or generally for all implementations.
if it's not a lot of work, can you please file another PR to add null guards for the typescript generator(s)? to me this approach seems more straightforward as I don't think we need 2 functions doing the same thing: one with null check and another one without null check. |
It's not too much. Do you want me to guard for null in any other generator as well, if need be, or wait until the issue occurs and we fix it then?
Agree. |
I opened three alternatives:
Let me know what you think @wing328. I think after seeing the three options side by side, my order of preference would be 3, 1, 2 |
thanks for creating these PRs. i'll take a look later this week |
@joscha I might have missed it. Why not simply use |
If it doesn't replace |
yes, hence why in each of the fix PRs |
@wing328 @macjohnny any more thoughts on this? I think after seeing the three options side by side, my order of preference would be 3, 1, 2 (see #19528 (comment)) |
Currently, generated Typescript-code has escaped
'
s, etc. in the generated comment parts. This is due to the fact, that we currently useescapeText
openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
Line 1100 in e914c40
everywhere, which has varying implementations for each target language. For
Typescript
it has:openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java
Lines 1073 to 1074 in e914c40
which results in the aforementioned escaped sequence.
Example:
(origin here)
This pull request only escapes unsafe characters (currently multiline comments) for the descriptions of parameters, etc.
PR checklist
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)closes #19553, #19554