Skip to content

Commit 38659b9

Browse files
claude[bot]bcherny
andauthored
feat: include array item descriptions in generated TypeScript
Fixes #660 by modifying the generator to include item descriptions when generating standalone array types. Array item descriptions are now included in the TypeScript comment as "Array items: [description]". Co-authored-by: bcherny <bcherny@users.noreply.github.com>
1 parent 43ba08b commit 38659b9

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/generator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,18 @@ function generateStandaloneInterface(ast: TNamedInterface, options: Options): st
360360
}
361361

362362
function generateStandaloneType(ast: ASTWithStandaloneName, options: Options): string {
363+
let comment = ast.comment
364+
365+
// For arrays, include item description in the comment if it exists
366+
if (ast.type === 'ARRAY' && hasComment(ast.params)) {
367+
const itemComment = ast.params.comment
368+
if (itemComment) {
369+
comment = comment ? `${comment}\n\nArray items:\n${itemComment}` : `Array items:\n${itemComment}`
370+
}
371+
}
372+
363373
return (
364-
(hasComment(ast) ? generateComment(ast.comment) + '\n' : '') +
374+
(comment ? generateComment(comment, ast.deprecated) + '\n' : '') +
365375
`export type ${toSafeString(ast.standaloneName)} = ${generateType(
366376
omit<AST>(ast, 'standaloneName') as AST /* TODO */,
367377
options,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
input: {
3+
$schema: 'http://json-schema.org/draft-07/schema#',
4+
title: 'peoples',
5+
type: 'array',
6+
description: '@group Shared/QueryString\n@description <adult>,<child age>|<child age>',
7+
items: {
8+
type: 'string',
9+
description: '@group Shared/QueryString/REGEXP\n@description travel peoples QueryString(<adult>,<child age>|<child age>|...)',
10+
pattern: '^\\d+,(?:\\d+)(?:-\\d+)*$',
11+
examples: ['2,5-7', '1,3-4-5'],
12+
},
13+
},
14+
expected: `/**
15+
* @group Shared/QueryString
16+
* @description <adult>,<child age>|<child age>
17+
*
18+
* Array items:
19+
* @group Shared/QueryString/REGEXP
20+
* @description travel peoples QueryString(<adult>,<child age>|<child age>|...)
21+
*/
22+
export type Peoples = string[];`
23+
}

0 commit comments

Comments
 (0)