Skip to content

Commit bd1fc64

Browse files
committed
Support modules that are reopened
1 parent 337e847 commit bd1fc64

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

src/metadataGeneration/typeResolver.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -689,19 +689,21 @@ export class TypeResolver {
689689
if (!moduleDeclarations.length) {
690690
throw new GenerateMetadataError(`No matching module declarations found for ${leftmostName}.`);
691691
}
692-
if (moduleDeclarations.length > 1) {
693-
throw new GenerateMetadataError(`Multiple matching module declarations found for ${leftmostName}; please make module declarations unique.`);
694-
}
695692

696-
if (ts.isEnumDeclaration(moduleDeclarations[0])) {
697-
statements = moduleDeclarations[0].members;
698-
} else {
699-
const moduleBlock = moduleDeclarations[0].body as ts.ModuleBlock;
700-
if (moduleBlock === null || moduleBlock.kind !== ts.SyntaxKind.ModuleBlock) {
701-
throw new GenerateMetadataError(`Module declaration found for ${leftmostName} has no body.`);
702-
}
703-
statements = moduleBlock.statements;
704-
}
693+
statements = Array.prototype.concat(
694+
...moduleDeclarations.map(declaration => {
695+
if (ts.isEnumDeclaration(declaration)) {
696+
return declaration.members;
697+
} else {
698+
const moduleBlock = declaration.body as ts.ModuleBlock;
699+
if (moduleBlock === null || moduleBlock.kind !== ts.SyntaxKind.ModuleBlock) {
700+
throw new GenerateMetadataError(`Module declaration found for ${leftmostName} has no body.`);
701+
}
702+
return moduleBlock.statements;
703+
}
704+
}),
705+
);
706+
705707
leftmost = leftmost.parent as ts.EntityName;
706708
}
707709

tests/fixtures/controllers/getController.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
///<reference path="../tsoaTestModule.d.ts" />
12
import { Readable } from 'stream';
23
import { Controller, Example, Get, OperationId, Query, Request, Route, SuccessResponse, Tags } from '../../../src';
34
import '../duplicateTestModel';
45
import { GenericModel, GetterClass, GetterInterface, GetterInterfaceHerited, TestClassModel, TestModel, TestSubModel, SimpleClassWithToJSON } from '../testModel';
56
import { ModelService } from './../services/modelService';
7+
import * as tsoaTestModule from 'tsoaTestModule';
68

79
@Route('GetTest')
810
export class GetTestController extends Controller {
@@ -78,6 +80,11 @@ export class GetTestController extends Controller {
7880
return {} as GetterInterfaceHerited;
7981
}
8082

83+
@Get('ModuleRedeclaration')
84+
public async getModuleRedeclaration(): Promise<tsoaTestModule.TestModel73> {
85+
return {} as tsoaTestModule.TestModel73;
86+
}
87+
8188
@Get('Multi')
8289
public async getMultipleModels(): Promise<TestModel[]> {
8390
return [new ModelService().getModel(), new ModelService().getModel(), new ModelService().getModel()];

tests/fixtures/testModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ interface GenericContainer<T, TSameNameDifferentValue> {
722722
}
723723

724724
/**
725-
* This should only be used inside GenericContainer to check it\'s
725+
* This should only be used inside GenericContainer to check its
726726
* type argument T gets propagated while TSameNameDifferentValue does not
727727
* and instead, the interface {@link TSameNameDifferentValue} is used.
728728
*/

tests/fixtures/tsoaTestModule.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'tsoaTestModule' {
2+
interface TestModel72 {
3+
value?: string;
4+
}
5+
}
6+
7+
declare module 'tsoaTestModule' {
8+
interface TestModel73 {
9+
value?: string;
10+
}
11+
}

0 commit comments

Comments
 (0)