Skip to content

Commit ee16c34

Browse files
committed
fix: Support response using inner interface
1 parent 45de0fa commit ee16c34

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

packages/cli/src/metadataGeneration/typeResolver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ export class TypeResolver {
596596
const isGlobalDeclaration = (mod: ts.ModuleDeclaration) => mod.name.kind === ts.SyntaxKind.Identifier && mod.name.text === 'global';
597597

598598
while (!ts.isSourceFile(actNode)) {
599+
if (ts.isBlock(actNode)) {
600+
break;
601+
}
599602
if (!(isFirst && ts.isEnumDeclaration(actNode)) && !ts.isModuleBlock(actNode)) {
600603
throwUnless(ts.isModuleDeclaration(actNode), new GenerateMetadataError(`This node kind is unknown: ${actNode.kind}`, type));
601604

tests/fixtures/controllers/getController.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ export class GetTestController extends Controller {
107107
return {} as GetterInterfaceHerited;
108108
}
109109

110+
@Get('InnerInterface')
111+
public async getInnerInterface() {
112+
interface InnerInterface {
113+
value?: string;
114+
}
115+
return { value: 'test' } as InnerInterface;
116+
}
117+
110118
@Get('ModuleRedeclarationAndNamespace')
111119
public async getModuleRedeclarationAndNamespace(): Promise<TsoaTest.TestModel73> {
112120
return {} as TsoaTest.TestModel73;

tests/unit/swagger/schemaDetails3.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4647,6 +4647,28 @@ describe('Definition generation for OpenAPI 3.0.0', () => {
46474647
expect(extensionPath['x-attKey8']).to.deep.equal({ test: { testArray: ['testVal1', true, null, ['testVal2', 'testVal3', 123, true, null]] } });
46484648
});
46494649

4650+
describe('Inner interface', () => {
4651+
it('should generate the proper schema', () => {
4652+
const ref = specDefault.spec.paths['/GetTest/InnerInterface'].get?.responses['200'].content?.['application/json']['schema']?.['$ref'];
4653+
expect(ref).to.equal('#/components/schemas/InnerInterface');
4654+
expect(getComponentSchema('InnerInterface', specDefault)).to.deep.equal({
4655+
additionalProperties: true,
4656+
description: undefined,
4657+
properties: {
4658+
value: {
4659+
default: undefined,
4660+
description: undefined,
4661+
example: undefined,
4662+
format: undefined,
4663+
type: 'string',
4664+
},
4665+
},
4666+
required: undefined,
4667+
type: 'object',
4668+
});
4669+
});
4670+
});
4671+
46504672
describe('module declarations with namespaces', () => {
46514673
it('should generate the proper schema for a model declared in a namespace in a module', () => {
46524674
/* tslint:disable:no-string-literal */

0 commit comments

Comments
 (0)