OpenAPITools / OpenAPITools/openapi-generator
[BUG][Typescript] Respect \n (line break) in description and other text fields
Nobody has claimed this yet.
- 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

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
- Generate
- Inspect the multi-line comments
/** */ - 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

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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