Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/openapi-generator/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ export function leadingComment(
commentString = commentString + endingSubstring;
}

const parsedComment = parseComment(commentString);
const parsedComment = parseComment(commentString, { spacing: 'preserve' });

for (const block of parsedComment) {
block.description = block.description.trim();
for (const tag of block.tags) {
tag.description = tag.description.trim();
}
}

return parsedComment;
}

Expand Down
82 changes: 78 additions & 4 deletions packages/openapi-generator/test/openapi/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,15 @@ export const route = h.httpRoute({
/**
* This is a bar param.
* @example { "foo": "bar" }
*/
*/
bar: t.record(t.string, t.string),
},
body: {
/**
* foo description
* @pattern ^[1-9][0-9]{4}$
* @example 12345
*/
*/
foo: t.number,
child: {
/**
Expand Down Expand Up @@ -840,7 +840,7 @@ export const route = h.httpRoute({
/**
* This is a foo description.
* @example BitGo Inc
*/
*/
foo: Foo,
bar: Bar,
},
Expand Down Expand Up @@ -979,7 +979,7 @@ export const route = h.httpRoute({
* @maxLength 10
* @example SomeInc
* @default BitgoInc
*/
*/
foo: t.string()
},
}),
Expand Down Expand Up @@ -1682,3 +1682,77 @@ testCase(
},
},
);

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: {},
},
});