OpenAPITools / OpenAPITools/openapi-generator

[BUG][Typescript] Respect \n (line break) in description and other text fields

Open
#6,164 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Line breaks in descriptions that are converted to comments are not respected in the generated typescript.

Example:

/**
 * Foo
 * # Hello  ## I'm a line break
 *
 * The version of the OpenAPI document: 0001
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
export interface Foo { 
    /**
     * # Hello  ## I'm a line break
     */
    bar?: string;
}

Should be:

/**
 * Foo
 * # Hello
 * 
 * ## I'm a line break
 *
 * The version of the OpenAPI document: 0001
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */
export interface Foo { 
    /**
     * # Hello
     * 
     * ## I'm a line break
     */
    bar?: string;
}

SwaggerUI correctly picks up on this
image

The issue is not isolated to models. This is also a problem in the services and possibly other places as well.

openapi-generator version

"@openapitools/openapi-generator-cli": "^1.0.12-4.3.0",

OpenAPI declaration file content or url

https://gist.github.com/snebjorn/2ccbde4db84ed08097a1b3f5ede420a9

Command line used for generation
// openapi-generator.config.json
{
  "supportsES6": true,
  "providedInRoot": true,
  "modelPropertyNaming": "original",
  "useSingleRequestParameter": true,
  "stringEnums": true
}

openapi-generator generate -g typescript-angular -c openapi-generator.config.json

Steps to reproduce
  1. Generate
  2. Inspect the multi-line comments /** */
  3. Observe that \n have just become spaces
Suggest a fix

The fix is to correctly insert line breaks where \n is found.
However every line break should not be respected. For example I don't think line break in titles make sense.
SwaggerUI seems to get this right, so probably just follow what that does.

For example these do not have line breaks even though the source have them

image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the typescript-angular client with the provided openapi-generator command, configuration, and declaration gist, then inspect multiline comments in the generated models and services. The change is done when escaped line breaks in description and other text fields produce separate comment lines, while title line breaks remain unexpanded as described.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.