Skip to content

Commit

Permalink
fix: Support response using inner interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoi2 committed Nov 29, 2024
1 parent 45de0fa commit ee16c34
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/cli/src/metadataGeneration/typeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ export class TypeResolver {
const isGlobalDeclaration = (mod: ts.ModuleDeclaration) => mod.name.kind === ts.SyntaxKind.Identifier && mod.name.text === 'global';

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

Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/controllers/getController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ export class GetTestController extends Controller {
return {} as GetterInterfaceHerited;
}

@Get('InnerInterface')
public async getInnerInterface() {
interface InnerInterface {
value?: string;
}
return { value: 'test' } as InnerInterface;
}

@Get('ModuleRedeclarationAndNamespace')
public async getModuleRedeclarationAndNamespace(): Promise<TsoaTest.TestModel73> {
return {} as TsoaTest.TestModel73;
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/swagger/schemaDetails3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4647,6 +4647,28 @@ describe('Definition generation for OpenAPI 3.0.0', () => {
expect(extensionPath['x-attKey8']).to.deep.equal({ test: { testArray: ['testVal1', true, null, ['testVal2', 'testVal3', 123, true, null]] } });
});

describe('Inner interface', () => {
it('should generate the proper schema', () => {
const ref = specDefault.spec.paths['/GetTest/InnerInterface'].get?.responses['200'].content?.['application/json']['schema']?.['$ref'];
expect(ref).to.equal('#/components/schemas/InnerInterface');
expect(getComponentSchema('InnerInterface', specDefault)).to.deep.equal({
additionalProperties: true,
description: undefined,
properties: {
value: {
default: undefined,
description: undefined,
example: undefined,
format: undefined,
type: 'string',
},
},
required: undefined,
type: 'object',
});
});
});

describe('module declarations with namespaces', () => {
it('should generate the proper schema for a model declared in a namespace in a module', () => {
/* tslint:disable:no-string-literal */
Expand Down

0 comments on commit ee16c34

Please sign in to comment.