[typescript] fix: escaped multiline comments; implementation option 1

JO
19d ago
+72-14

Currently, generated Typescript-code has escaped 's, etc. in the generated comment parts. This is due to the fact, that we currently use escapeText

https://github.com/OpenAPITools/openapi-generator/blob/e914c4098b44ac734d3dd21300d433f6cb2974a5/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L1100

everywhere, which has varying implementations for each target language. For Typescript it has:

https://github.com/OpenAPITools/openapi-generator/blob/e914c4098b44ac734d3dd21300d433f6cb2974a5/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java#L1073-L1074

which results in the aforementioned escaped sequence.

Example:
Screenshot 2024-09-04 at 2 20 58 PM
(origin here)

This pull request only escapes unsafe characters (currently multiline comments) for the descriptions of parameters, etc.

Note: The current implementation of escapeUnsafeCharacters does not guard for null, which is a possibility for any string passed. escapeText has the null guard. There are about a dozen @Overrides for escapeUnsafeCharacters, none of them guarding null (as it hasn't been used directly before, but only through escapeText, which has the guard). There were two options:

  1. Add null guards to all existing implementations
  2. Introduce a wrapper function like escapeText that guards for null and calls to escapeUnsafeCharacters

I chose 2) as it seemed more resilient, testable and also makes sure that other implementations out there and new ones in pull requests keep on working as expected. Let me know if you prefer 1) instead.

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 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee: @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04)

closes #19553, #19554