microsoft / typespec

https://typespec.io/
MIT License
4.07k stars 187 forks source link

[Bug]: tsp-openapi3: automatic doc newlines break code spans #3835

Closed Arithmomaniac closed 1 month ago

Arithmomaniac commented 1 month ago

Describe the bug

the tsp-openapi3 tool (as of @typespec/openapi3@0.58.0-dev.6) automatically breaks long documentation lines into newlines.

For example, the following description:

"description": "An array containing the type names of the sections of this text. The length of sectionNames gives the depth of the structure of this text. For example, Kohelet `([\"Chapter\", \"Verse\"])` has depth 2, while Mishneh Torah `([\"Book\", \"Topic\", \"Section\", \"Law\"])` has depth 4. Comparing this depth to the depth of sections will show if the request was for the lowest level, or a higher level, of the text.",

results in this output:

/**
* An array containing the type names of the sections of this text. The length of
* sectionNames gives the depth of the structure of this text. For example,
* Kohelet `(["Chapter", "Verse"])` has depth 2, while Mishneh Torah `(["Book",
* "Topic", "Section", "Law"])` has depth 4. Comparing this depth to the depth of
* sections will show if the request was for the lowest level, or a higher level,
* of the text.
*/

This results in an error being thrown during the conversion because one of the code spans has been split between two different lines:

error: {
    code: 'unterminated',
    severity: 'error',
    message: 'Unterminated doc code span.',
    target: { file: [Object], pos: 9845, end: 9855 }
  }

I personally don't think this long-line-breaking is desirable behavior for a migration (at the very least, it should be optional for people who need maximum fidelity for a tool like ReadMe), but at the very least, it should either (a) be disable-able, or (b) be smart enough to not break code spans.

Reproduction

  1. Download https://github.com/Sefaria/Sefaria-Project/blob/6faae1e92f428c05daae64d256b891f2e055dd2e/docs/openAPI.json
  2. Run npx -p @typespec/openapi3@next tsp-openapi3 openAPI.json --output-dir tsp

Checklist

chrisradek commented 1 month ago

@Arithmomaniac Thank you for opening up this issue!

3839 should address this. The tool will no longer automatically add line breaks but will still honor line breaks that exist in the original documentation string.