From 29ae90d0140e4082b968de2ad55940953f04425e Mon Sep 17 00:00:00 2001 From: Josh Chappelow Date: Sat, 2 Nov 2024 23:38:58 +0900 Subject: [PATCH 1/2] falsy check --- packages/cli/src/metadataGeneration/exceptions.ts | 10 +++++++--- tests/fixtures/controllers/getController.ts | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/metadataGeneration/exceptions.ts b/packages/cli/src/metadataGeneration/exceptions.ts index ae10a6441..d5a0f3702 100644 --- a/packages/cli/src/metadataGeneration/exceptions.ts +++ b/packages/cli/src/metadataGeneration/exceptions.ts @@ -11,7 +11,11 @@ export class GenerateMetadataError extends Error { } export class GenerateMetaDataWarning { - constructor(private message: string, private node: Node | TypeNode, private onlyCurrent = false) { } + constructor( + private message: string, + private node: Node | TypeNode, + private onlyCurrent = false, + ) {} toString() { return `Warning: ${this.message}\n${prettyLocationOfNode(this.node)}\n${prettyTroubleCause(this.node, this.onlyCurrent)}`; @@ -34,9 +38,9 @@ export function prettyLocationOfNode(node: Node | TypeNode) { export function prettyTroubleCause(node: Node | TypeNode, onlyCurrent = false) { let name: string; if (onlyCurrent || !node.parent) { - name = node.pos !== -1 ? node.getText() : ((node as any).name?.text || ''); + name = node.pos !== -1 && node.parent ? node.getText() : (node as any).name?.text || ''; } else { - name = node.parent.pos !== -1 ? node.parent.getText() : ((node as any).parent.name?.text || ''); + name = node.parent.pos !== -1 ? node.parent.getText() : (node as any).parent.name?.text || ''; } return `This was caused by '${name}'`; } diff --git a/tests/fixtures/controllers/getController.ts b/tests/fixtures/controllers/getController.ts index 11d753ae0..68d23ef14 100644 --- a/tests/fixtures/controllers/getController.ts +++ b/tests/fixtures/controllers/getController.ts @@ -112,6 +112,14 @@ export class GetTestController extends Controller { return {} as TsoaTest.TestModel73; } + @Get('NamespaceWithTypeCastedObject') + public async getNamespaceWithTypeCastedObject() { + const test = { value: 'test' }; + return { + value: test as TsoaTest.TestModel73, + }; + } + @Get('Multi') public async getMultipleModels(): Promise { return [new ModelService().getModel(), new ModelService().getModel(), new ModelService().getModel()]; From 33e951ab0c9116cae9c914ce0b243126d6fa5354 Mon Sep 17 00:00:00 2001 From: Josh Chappelow Date: Sun, 3 Nov 2024 02:45:14 +0900 Subject: [PATCH 2/2] test: unit test --- tests/unit/swagger/schemaDetails3.spec.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/swagger/schemaDetails3.spec.ts b/tests/unit/swagger/schemaDetails3.spec.ts index b2c470db7..20b92681c 100644 --- a/tests/unit/swagger/schemaDetails3.spec.ts +++ b/tests/unit/swagger/schemaDetails3.spec.ts @@ -4669,6 +4669,12 @@ describe('Definition generation for OpenAPI 3.0.0', () => { type: 'object', }); }); + + it('should generate schema with namespace type casted object', () => { + const response = specDefault.spec.paths['/GetTest/NamespaceWithTypeCastedObject']?.get?.responses; + + expect(response).to.have.all.keys('200'); + }); }); describe('@Res responses', () => {