Skip to content

Commit

Permalink
feat(http): allow using unknown/any/never types that are nominal
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Jan 31, 2024
1 parent e44f9e7 commit 3221ff0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/http/src/request-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 27 additions & 0 deletions packages/http/tests/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,3 +1556,30 @@ test('dependency injection unknown', async () => {
const httpKernel = createHttpKernel([Controller], [provide<A>(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> = T & { user: User };

type DocUser = PopulateUser<Doc>;

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<DocUser>({useValue: user})]);
expect((await httpKernel.request(HttpRequest.GET('/user/peter'))).json).toEqual(['peter', 1, 'peter2']);
})

0 comments on commit 3221ff0

Please sign in to comment.