Skip to content

Commit ca2068d

Browse files
authored
Merge pull request #1724 from mdoi2/fix/inner_interface
fix: Support response using inner interface
2 parents fbfd0ca + a543366 commit ca2068d

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
@@ -4660,6 +4660,28 @@ describe('Definition generation for OpenAPI 3.0.0', () => {
46604660
expect(extensionPath['x-attKey8']).to.deep.equal({ test: { testArray: ['testVal1', true, null, ['testVal2', 'testVal3', 123, true, null]] } });
46614661
});
46624662

4663+
describe('Inner interface', () => {
4664+
it('should generate the proper schema', () => {
4665+
const ref = specDefault.spec.paths['/GetTest/InnerInterface'].get?.responses['200'].content?.['application/json']['schema']?.['$ref'];
4666+
expect(ref).to.equal('#/components/schemas/InnerInterface');
4667+
expect(getComponentSchema('InnerInterface', specDefault)).to.deep.equal({
4668+
additionalProperties: true,
4669+
description: undefined,
4670+
properties: {
4671+
value: {
4672+
default: undefined,
4673+
description: undefined,
4674+
example: undefined,
4675+
format: undefined,
4676+
type: 'string',
4677+
},
4678+
},
4679+
required: undefined,
4680+
type: 'object',
4681+
});
4682+
});
4683+
});
4684+
46634685
describe('module declarations with namespaces', () => {
46644686
it('should generate the proper schema for a model declared in a namespace in a module', () => {
46654687
/* tslint:disable:no-string-literal */

0 commit comments

Comments
 (0)