Skip to content

Commit

Permalink
Emit comments for literal unions (fix #475)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Cherny committed Aug 7, 2022
1 parent 34de194 commit 91cd642
Show file tree
Hide file tree
Showing 4 changed files with 177,073 additions and 31,690 deletions.
4 changes: 3 additions & 1 deletion src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ function generateRawType(ast: AST, options: Options): string {
* Generate a Union or Intersection
*/
function generateSetOperation(ast: TIntersection | TUnion, options: Options): string {
const members = (ast as TUnion).params.map(_ => generateType(_, options))
const members = (ast as TUnion).params.map(_ =>
[_.comment ? generateComment(_.comment) : null, generateType(_, options)].filter(Boolean).join('\n')
)
const separator = ast.type === 'UNION' ? '|' : '&'
return members.length === 1 ? members[0] : '(' + members.join(' ' + separator + ' ') + ')'
}
Expand Down
208,753 changes: 177,064 additions & 31,689 deletions test/__snapshots__/test/test.ts.md

Large diffs are not rendered by default.

Binary file modified test/__snapshots__/test/test.ts.snap
Binary file not shown.
6 changes: 6 additions & 0 deletions test/e2e/enum.4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const input = {
oneOf: [
{const: 'a', description: 'First comment (a).'},
{const: 'b', description: 'Second comment (b).'}
]
}

0 comments on commit 91cd642

Please sign in to comment.