diff --git a/src/generator.ts b/src/generator.ts index 8f3e97c0..fb8d23b0 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -316,12 +316,14 @@ function generateInterface(ast: TInterface, options: Options): string { ) } -function generateComment(comment: string, deprecated?: boolean): string { +function generateComment(comment?: string, deprecated?: boolean): string { const commentLines = ['/**'] if (deprecated) { commentLines.push(' * @deprecated') } - commentLines.push(...comment.split('\n').map(_ => ' * ' + _)) + if (typeof comment !== 'undefined') { + commentLines.push(...comment.split('\n').map(_ => ' * ' + _)) + } commentLines.push(' */') return commentLines.join('\n') } diff --git a/test/__snapshots__/test/test.ts.md b/test/__snapshots__/test/test.ts.md index a5b3e6e9..c83bd491 100644 --- a/test/__snapshots__/test/test.ts.md +++ b/test/__snapshots__/test/test.ts.md @@ -827,7 +827,6 @@ Generated by [AVA](https://avajs.dev). export interface ExampleSchema {␊ /**␊ * @deprecated␊ - * nested comment␊ */␊ firstName: string;␊ /**␊ @@ -839,6 +838,7 @@ Generated by [AVA](https://avajs.dev). * nested comment␊ */␊ lastName?: string;␊ + description?: string;␊ }␊ ` diff --git a/test/__snapshots__/test/test.ts.snap b/test/__snapshots__/test/test.ts.snap index 5dec9a4a..4d3e02b7 100644 Binary files a/test/__snapshots__/test/test.ts.snap and b/test/__snapshots__/test/test.ts.snap differ diff --git a/test/e2e/deprecated.ts b/test/e2e/deprecated.ts index dbab60dd..6d8716f4 100644 --- a/test/e2e/deprecated.ts +++ b/test/e2e/deprecated.ts @@ -5,10 +5,10 @@ export const input = { deprecated: true, description: 'comment', properties: { + // https://github.com/bcherny/json-schema-to-typescript/issues/548 firstName: { type: 'string', deprecated: true, - description: 'nested comment', }, middleName: { type: 'string', @@ -20,6 +20,10 @@ export const input = { deprecated: false, description: 'nested comment', }, + // https://github.com/bcherny/json-schema-to-typescript/issues/540 + description: { + type: 'string', + }, }, additionalProperties: false, required: ['firstName'],