From e0f9a56c1211c93f8f3a7cbff6c5d0fc3915c83b Mon Sep 17 00:00:00 2001 From: Dereck Tu Date: Fri, 16 Jan 2026 12:22:21 -0500 Subject: [PATCH] feat: default to preserving line breaks Ticket: DX-2753 This commit defaults the tool to preserving line breaks/spacing. The changes are effectively a redo of https://github.com/BitGo/api-ts/pull/1081/changes --- packages/openapi-generator/src/comments.ts | 5 +- .../test/openapi/comments.test.ts | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/packages/openapi-generator/src/comments.ts b/packages/openapi-generator/src/comments.ts index 1809ab99..36879f2d 100644 --- a/packages/openapi-generator/src/comments.ts +++ b/packages/openapi-generator/src/comments.ts @@ -77,10 +77,7 @@ export function leadingComment( commentString = commentString.replace(/@preserveLineBreaks\s*/g, ''); } - const parsedComment = parseComment( - commentString, - shouldPreserveLineBreaks ? { spacing: 'preserve' } : undefined, - ); + const parsedComment = parseComment(commentString, { spacing: 'preserve' }); for (const block of parsedComment) { block.description = block.description.trim(); diff --git a/packages/openapi-generator/test/openapi/comments.test.ts b/packages/openapi-generator/test/openapi/comments.test.ts index f4660d3b..4b461a5f 100644 --- a/packages/openapi-generator/test/openapi/comments.test.ts +++ b/packages/openapi-generator/test/openapi/comments.test.ts @@ -2111,3 +2111,77 @@ testCase('route with multibyte chars', ROUTE_WITH_MULTIBYTE_CHARS, { }, }, }); + +const ROUTE_WITH_MARKDOWN_LIST = ` +import * as t from 'io-ts'; +import * as h from '@api-ts/io-ts-http'; + +/** + * A route with a list in the comment + * + * @operationId api.v1.list + * @tag Test Routes + */ +export const route = h.httpRoute({ + path: '/list', + method: 'GET', + request: h.httpRequest({ + query: { + /** + * The permissions granted by this access token. + * + * - \`all\` - Access all actions in the test environment. + * - \`crypto_compare\` - Call CryptoCompare API. + */ + permissions: t.string, + }, + }), + response: { + 200: t.string + }, +}); +`; + +testCase('route with markdown list in comment', ROUTE_WITH_MARKDOWN_LIST, { + openapi: '3.0.3', + info: { + title: 'Test', + version: '1.0.0', + }, + paths: { + '/list': { + get: { + summary: 'A route with a list in the comment', + operationId: 'api.v1.list', + tags: ['Test Routes'], + parameters: [ + { + name: 'permissions', + in: 'query', + required: true, + schema: { + type: 'string', + }, + description: + 'The permissions granted by this access token.\n\n- `all` - Access all actions in the test environment.\n- `crypto_compare` - Call CryptoCompare API.', + }, + ], + responses: { + 200: { + description: 'OK', + content: { + 'application/json': { + schema: { + type: 'string', + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: {}, + }, +});