From 3221ff05ad2a2d426aa8da24c94678a672942831 Mon Sep 17 00:00:00 2001 From: "Marc J. Schmidt" Date: Wed, 31 Jan 2024 17:32:02 +0100 Subject: [PATCH] feat(http): allow using unknown/any/never types that are nominal --- packages/http/src/request-parser.ts | 1 + packages/http/tests/router.spec.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/http/src/request-parser.ts b/packages/http/src/request-parser.ts index 055abaded..ad324243b 100644 --- a/packages/http/src/request-parser.ts +++ b/packages/http/src/request-parser.ts @@ -156,6 +156,7 @@ export function parseRoutePathToRegex(path: string, params: ReflectionParameter[ } function isTypeUnknown(type: Type): boolean { + if (type.id) return false; //if is has an id we treat it as nominal type return type.kind === ReflectionKind.unknown || type.kind === ReflectionKind.any || type.kind === ReflectionKind.never; } diff --git a/packages/http/tests/router.spec.ts b/packages/http/tests/router.spec.ts index e6a51f6e2..e5de2907e 100644 --- a/packages/http/tests/router.spec.ts +++ b/packages/http/tests/router.spec.ts @@ -1556,3 +1556,30 @@ test('dependency injection unknown', async () => { const httpKernel = createHttpKernel([Controller], [provide(Service)]); expect((await httpKernel.request(HttpRequest.GET('/user/peter'))).text).toEqual('Not found'); }); + +test('disabled reflection', async () => { + type User = {username: string}; + type Doc = {id: number}; + + /** @reflection never */ + type PopulateUser = T & { user: User }; + + type DocUser = PopulateUser; + + const user: DocUser = { + id: 1, + user: { + username: 'peter2' + } + } + + class Controller { + @http.GET('user/:name') + async anyReq(name: string, user: DocUser) { + return [name, user.id, user.user.username]; + } + } + + const httpKernel = createHttpKernel([Controller], [provide({useValue: user})]); + expect((await httpKernel.request(HttpRequest.GET('/user/peter'))).json).toEqual(['peter', 1, 'peter2']); +})