Skip to content

Commit bfd6beb

Browse files
committed
fix: support multiline descriptions
Ticket: DX-1136
1 parent c03229f commit bfd6beb

File tree

2 files changed

+87
-5
lines changed

2 files changed

+87
-5
lines changed

packages/openapi-generator/src/comments.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,15 @@ export function leadingComment(
4040
commentString = commentString + endingSubstring;
4141
}
4242

43-
const parsedComment = parseComment(commentString);
43+
const parsedComment = parseComment(commentString, { spacing: 'preserve' });
44+
45+
for (const block of parsedComment) {
46+
block.description = block.description.trim();
47+
for (const tag of block.tags) {
48+
tag.description = tag.description.trim();
49+
}
50+
}
51+
4452
return parsedComment;
4553
}
4654

packages/openapi-generator/test/openapi/comments.test.ts

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,15 +693,15 @@ export const route = h.httpRoute({
693693
/**
694694
* This is a bar param.
695695
* @example { "foo": "bar" }
696-
*/
696+
*/
697697
bar: t.record(t.string, t.string),
698698
},
699699
body: {
700700
/**
701701
* foo description
702702
* @pattern ^[1-9][0-9]{4}$
703703
* @example 12345
704-
*/
704+
*/
705705
foo: t.number,
706706
child: {
707707
/**
@@ -840,7 +840,7 @@ export const route = h.httpRoute({
840840
/**
841841
* This is a foo description.
842842
* @example BitGo Inc
843-
*/
843+
*/
844844
foo: Foo,
845845
bar: Bar,
846846
},
@@ -979,7 +979,7 @@ export const route = h.httpRoute({
979979
* @maxLength 10
980980
* @example SomeInc
981981
* @default BitgoInc
982-
*/
982+
*/
983983
foo: t.string()
984984
},
985985
}),
@@ -1682,3 +1682,77 @@ testCase(
16821682
},
16831683
},
16841684
);
1685+
1686+
const ROUTE_WITH_MARKDOWN_LIST = `
1687+
import * as t from 'io-ts';
1688+
import * as h from '@api-ts/io-ts-http';
1689+
1690+
/**
1691+
* A route with a list in the comment
1692+
*
1693+
* @operationId api.v1.list
1694+
* @tag Test Routes
1695+
*/
1696+
export const route = h.httpRoute({
1697+
path: '/list',
1698+
method: 'GET',
1699+
request: h.httpRequest({
1700+
query: {
1701+
/**
1702+
* The permissions granted by this access token.
1703+
*
1704+
* - \`all\` - Access all actions in the test environment.
1705+
* - \`crypto_compare\` - Call CryptoCompare API.
1706+
*/
1707+
permissions: t.string,
1708+
},
1709+
}),
1710+
response: {
1711+
200: t.string
1712+
},
1713+
});
1714+
`;
1715+
1716+
testCase('route with markdown list in comment', ROUTE_WITH_MARKDOWN_LIST, {
1717+
openapi: '3.0.3',
1718+
info: {
1719+
title: 'Test',
1720+
version: '1.0.0',
1721+
},
1722+
paths: {
1723+
'/list': {
1724+
get: {
1725+
summary: 'A route with a list in the comment',
1726+
operationId: 'api.v1.list',
1727+
tags: ['Test Routes'],
1728+
parameters: [
1729+
{
1730+
name: 'permissions',
1731+
in: 'query',
1732+
required: true,
1733+
schema: {
1734+
type: 'string',
1735+
},
1736+
description:
1737+
'The permissions granted by this access token.\n\n- `all` - Access all actions in the test environment.\n- `crypto_compare` - Call CryptoCompare API.',
1738+
},
1739+
],
1740+
responses: {
1741+
200: {
1742+
description: 'OK',
1743+
content: {
1744+
'application/json': {
1745+
schema: {
1746+
type: 'string',
1747+
},
1748+
},
1749+
},
1750+
},
1751+
},
1752+
},
1753+
},
1754+
},
1755+
components: {
1756+
schemas: {},
1757+
},
1758+
});

0 commit comments

Comments
 (0)