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
6 changes: 4 additions & 2 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/test/test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ Generated by [AVA](https://avajs.dev).
export interface ExampleSchema {␊
/**␊
* @deprecated␊
* nested comment␊
*/␊
firstName: string;␊
/**␊
Expand All @@ -839,6 +838,7 @@ Generated by [AVA](https://avajs.dev).
* nested comment␊
*/␊
lastName?: string;␊
description?: string;␊
}␊
`

Expand Down
Binary file modified test/__snapshots__/test/test.ts.snap
Binary file not shown.
6 changes: 5 additions & 1 deletion test/e2e/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'],
Expand Down