-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tsp-openapi3 automatic doc newlines logic (#3839)
Fixes #3835 `tsp-openapi3` will no longer automatically attempt to wrap documentation strings based on maximum column width. It will still honor any line breaks that exist in the original documentation when generating doc strings. --------- Co-authored-by: Christopher Radek <Christopher.Radek@microsoft.com>
- Loading branch information
1 parent
0d85077
commit 65a0288
Showing
4 changed files
with
109 additions
and
53 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/tsp-openapi3-fix-doc-newlines-2024-6-15-10-28-34.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
changeKind: fix | ||
packages: | ||
- "@typespec/openapi3" | ||
--- | ||
|
||
Updates tsp-openapi3 doc line wrapping to only automatically create newlines when they are present in the original documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { strictEqual } from "assert"; | ||
import { it } from "vitest"; | ||
import { generateDocs } from "../../src/cli/actions/convert/utils/docs.js"; | ||
|
||
it("returns empty string for empty docs", () => { | ||
strictEqual(generateDocs(""), ""); | ||
strictEqual(generateDocs([]), ""); | ||
}); | ||
|
||
it("returns single line doc", () => { | ||
strictEqual( | ||
generateDocs("Hello, World!"), | ||
` | ||
/** | ||
* Hello, World! | ||
*/ | ||
`.trim() | ||
); | ||
}); | ||
|
||
it("returns multi-line doc", () => { | ||
strictEqual( | ||
generateDocs(["Hello,", "World!"]), | ||
` | ||
/** | ||
* Hello, | ||
* World! | ||
*/`.trim() | ||
); | ||
}); | ||
|
||
it("returns multi-line docs when they contain newline characters", () => { | ||
strictEqual( | ||
generateDocs("Hello,\nWorld!"), | ||
` | ||
/** | ||
* Hello, | ||
* World! | ||
*/`.trim() | ||
); | ||
}); | ||
|
||
it("does not automatically apply line-wrapping for very long lines", () => { | ||
const longLine = "This is a long line".repeat(20); // 380 characters | ||
strictEqual( | ||
generateDocs(longLine), | ||
` | ||
/** | ||
* ${longLine} | ||
*/`.trim() | ||
); | ||
}); | ||
|
||
it("handles different newline breaks", () => { | ||
const scenarios = ["Hello,\nWorld!", "Hello,\rWorld!", "Hello,\r\nWorld!"]; | ||
|
||
for (const scenario of scenarios) { | ||
strictEqual( | ||
generateDocs(scenario), | ||
` | ||
/** | ||
* Hello, | ||
* World! | ||
*/`.trim() | ||
); | ||
} | ||
}); | ||
|
||
it("uses doc generator for @ and */", () => { | ||
strictEqual(generateDocs("Hello, @World!"), `@doc("Hello, @World!")`); | ||
|
||
strictEqual(generateDocs("Hello, */World!"), `@doc("Hello, */World!")`); | ||
}); | ||
|
||
it("supports multi-line with decorator", () => { | ||
strictEqual( | ||
generateDocs(["Hello,", "@World!"]), | ||
` | ||
@doc(""" | ||
Hello, | ||
@World! | ||
""")`.trim() | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters