Skip to content

Commit ef1286f

Browse files
committed
fix: ensure correct void output types
1 parent 925f177 commit ef1286f

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

lib/process-document.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ export async function processOpenApiDocument(
8686
overwrite: true,
8787
});
8888

89-
const outputTypes: (InterfaceDeclaration | TypeAliasDeclaration)[] = [];
89+
const outputTypes: (InterfaceDeclaration | TypeAliasDeclaration | 'void')[] =
90+
[];
9091

9192
const refs = await $RefParser.default.resolve(schema);
9293

@@ -570,6 +571,8 @@ export async function processOpenApiDocument(
570571
func.setReturnType(retVal);
571572
classDeclaration.getExtends()?.addTypeArgument('void');
572573

574+
outputTypes.push('void');
575+
573576
jsdoc.addTag({
574577
tagName: 'returns',
575578
text: `{${retVal}} HTTP ${statusCode}`,
@@ -686,7 +689,9 @@ export async function processOpenApiDocument(
686689
...new Set(inputTypes.map((t) => t.getName())),
687690
);
688691
const outputUnion = createUnion(
689-
...new Set(outputTypes.map((t) => t.getName())),
692+
...new Set(
693+
outputTypes.map((t) => (typeof t === 'string' ? t : t.getName())),
694+
),
690695
);
691696

692697
const allInputs = inputUnion
@@ -723,10 +728,12 @@ export async function processOpenApiDocument(
723728

724729
clientFile.addImportDeclaration({
725730
moduleSpecifier: typesModuleSpecifier,
726-
namedImports: [...new Set([...inputTypes, ...outputTypes])].map((t) => ({
727-
name: t.getName(),
728-
isTypeOnly: true,
729-
})),
731+
namedImports: [...new Set([...inputTypes, ...outputTypes])]
732+
.filter(<T>(t: T | 'void'): t is T => t !== 'void')
733+
.map((t) => ({
734+
name: t.getName(),
735+
isTypeOnly: true,
736+
})),
730737
});
731738

732739
const clientClassDeclaration = clientFile.addClass({

0 commit comments

Comments
 (0)