diff --git a/packages/cli/src/routeGeneration/templates/express.hbs b/packages/cli/src/routeGeneration/templates/express.hbs index 743b50f65..dda88ac5e 100644 --- a/packages/cli/src/routeGeneration/templates/express.hbs +++ b/packages/cli/src/routeGeneration/templates/express.hbs @@ -24,6 +24,11 @@ const multer = require('multer'); const upload = multer({{{json multerOpts}}}); {{/if}} +{{#if authenticationModule}} +const expressAuthenticationRecasted = expressAuthentication as (req: ExRequest, securityName: string, scopes?: string[], res?: ExResponse) => Promise; +{{/if}} + + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa const models: TsoaRoute.Models = { @@ -141,7 +146,7 @@ export function RegisterRoutes(app: Router) { for (const name in secMethod) { secMethodAndPromises.push( - expressAuthentication(request, name, secMethod[name], response) + expressAuthenticationRecasted(request, name, secMethod[name], response) .catch(pushAndRethrow) ); } @@ -153,7 +158,7 @@ export function RegisterRoutes(app: Router) { } else { for (const name in secMethod) { secMethodOrPromises.push( - expressAuthentication(request, name, secMethod[name], response) + expressAuthenticationRecasted(request, name, secMethod[name], response) .catch(pushAndRethrow) ); } diff --git a/packages/cli/src/routeGeneration/templates/koa.hbs b/packages/cli/src/routeGeneration/templates/koa.hbs index 17a9bb2ea..59273f272 100644 --- a/packages/cli/src/routeGeneration/templates/koa.hbs +++ b/packages/cli/src/routeGeneration/templates/koa.hbs @@ -14,7 +14,7 @@ import { koaAuthentication } from '{{authenticationModule}}'; import { iocContainer } from '{{iocModule}}'; import type { IocContainer, IocContainerFactory } from '@tsoa/runtime'; {{/if}} -import type { Context, Next, Middleware } from 'koa'; +import type { Context, Next, Middleware, Request as KRequest, Response as KResponse } from 'koa'; import type * as KoaRouter from '@koa/router'; {{#if useFileUploads}} {{#if esm}} @@ -24,6 +24,10 @@ const multer = require('@koa/multer'); {{/if}} const upload = multer({{{json multerOpts}}}); {{/if}} +{{#if authenticationModule}} +const koaAuthenticationRecasted = koaAuthentication as (req: KRequest, securityName: string, scopes?: string[], res?: KResponse) => Promise; +{{/if}} + // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa @@ -140,7 +144,7 @@ export function RegisterRoutes(router: KoaRouter) { for (const name in secMethod) { secMethodAndPromises.push( - koaAuthentication(context.request, name, secMethod[name], context.response) + koaAuthenticationRecasted(context.request, name, secMethod[name], context.response) .catch(pushAndRethrow) ); } @@ -150,7 +154,7 @@ export function RegisterRoutes(router: KoaRouter) { } else { for (const name in secMethod) { secMethodOrPromises.push( - koaAuthentication(context.request, name, secMethod[name], context.response) + koaAuthenticationRecasted(context.request, name, secMethod[name], context.response) .catch(pushAndRethrow) ); } diff --git a/tests/fixtures/inversify-cpg/authentication.ts b/tests/fixtures/inversify-cpg/authentication.ts index 7d5223e26..2998f36fc 100644 --- a/tests/fixtures/inversify-cpg/authentication.ts +++ b/tests/fixtures/inversify-cpg/authentication.ts @@ -1,6 +1,6 @@ import * as express from 'express'; -export function expressAuthentication(req: express.Request, name: string, _scopes: string[] | undefined, res: express.Response): Promise { +export function expressAuthentication(req: express.Request, name: string, _scopes: string[] | undefined): Promise { if (req.query && req.query.tsoa && req.query.tsoa === 'abc123456') { return Promise.resolve({}); } else { diff --git a/tests/fixtures/koaNoAdditional/authentication.ts b/tests/fixtures/koaNoAdditional/authentication.ts index 1857c0ee6..0010152d1 100644 --- a/tests/fixtures/koaNoAdditional/authentication.ts +++ b/tests/fixtures/koaNoAdditional/authentication.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'koa'; -export function koaAuthentication(request: Request, name: string, scopes: string[] | undefined, response: Response): Promise { +export function koaAuthentication(request: Request, name: string, scopes: string[] | undefined): Promise { if (name === 'api_key') { let token; if (request.query && request.query.access_token) {