Skip to content

Commit dde6e9e

Browse files
authored
Merge pull request bcherny#191 from sokra/bugfix/optimize-custom-type
fix bug when optimizing custom types
2 parents 397a9ed + 23b1823 commit dde6e9e

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

src/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function generateType(ast: AST, options: Options): string {
158158
+ ast.params.map(_ => generateType(_, options)).join(', ')
159159
+ ']'
160160
case 'UNION': return generateSetOperation(ast, options)
161-
case 'CUSTOM_TYPE': return ast.param
161+
case 'CUSTOM_TYPE': return ast.params
162162
}
163163
}
164164

src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function parseNonLiteral(
104104
return set({
105105
comment: schema.description,
106106
keyName,
107-
param: schema.tsType!,
107+
params: schema.tsType!,
108108
standaloneName: standaloneName(schema, keyNameFromDefinition, usedNames),
109109
type: 'CUSTOM_TYPE'
110110
})

src/types/AST.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface TUnion extends AbstractAST {
115115

116116
export interface TCustomType extends AbstractAST {
117117
type: 'CUSTOM_TYPE'
118-
param: string
118+
params: string
119119
}
120120

121121
//////////////////////////////////////////// literals

test/__snapshots__/test/test.js.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ Generated by [AVA](https://ava.li).
937937
export interface OptimizableSchema {␊
938938
bar: string | number;␊
939939
foo: any;␊
940+
fooBar: A | B;␊
940941
[k: string]: any;␊
941942
}␊
942943
`

test/__snapshots__/test/test.js.snap

6 Bytes
Binary file not shown.

test/e2e/optimize.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ export const input = {
1414
{ type: 'any' },
1515
{ type: 'integer' }
1616
]
17+
},
18+
fooBar: {
19+
anyOf: [
20+
{ tsType: 'A' },
21+
{ tsType: 'A' },
22+
{ tsType: 'B' },
23+
{ tsType: 'A' },
24+
{ tsType: 'B' }
25+
]
1726
}
1827
},
19-
required: ['bar', 'foo'],
28+
required: ['bar', 'foo', 'fooBar'],
2029
title: 'Optimizable Schema',
2130
type: 'object'
2231
}

0 commit comments

Comments
 (0)