From f29665fb01d2527ca901ef489bf0777d1b591027 Mon Sep 17 00:00:00 2001 From: Adarsha Lalchan Date: Tue, 3 Oct 2023 13:56:22 +0545 Subject: [PATCH] added ability to pass multerInstance into generateRoute --- .../cli/src/routeGeneration/templates/express.hbs | 11 ++++++++--- packages/runtime/src/metadataGeneration/tsoa.ts | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/routeGeneration/templates/express.hbs b/packages/cli/src/routeGeneration/templates/express.hbs index b05f33fbb..fd0a574c0 100644 --- a/packages/cli/src/routeGeneration/templates/express.hbs +++ b/packages/cli/src/routeGeneration/templates/express.hbs @@ -12,7 +12,7 @@ import { expressAuthentication } from '{{authenticationModule}}'; {{/if}} {{#if iocModule}} import { iocContainer } from '{{iocModule}}'; -import type { IocContainer, IocContainerFactory } from '@tsoa/runtime'; +import type { IocContainer, IocContainerFactory, RegisterRoutesOptions } from '@tsoa/runtime'; {{/if}} import type { RequestHandler, Router } from 'express'; {{#if useFileUploads}} @@ -21,7 +21,7 @@ import multer from 'multer'; {{else}} const multer = require('multer'); {{/if}} -const upload = multer({{{json multerOpts}}}); +let upload = multer({{{json multerOpts}}}); {{/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 @@ -54,11 +54,16 @@ const validationService = new ValidationService(models); // 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 -export function RegisterRoutes(app: Router) { +export function RegisterRoutes(app: Router, registerOptions: RegisterRoutesOptions = {}) { // ########################################################################################################### // NOTE: If you do not see routes for all of your controllers in this file, then you might not have informed tsoa of where to look // Please look into the "controllerPathGlobs" config option described in the readme: https://github.com/lukeautry/tsoa // ########################################################################################################### + {{#if useFileUploads}} + if(registerOptions.multer){ + upload = registerOptions.multer, + } + {{/if}} {{#each controllers}} {{#each actions}} app.{{method}}('{{fullPath}}', diff --git a/packages/runtime/src/metadataGeneration/tsoa.ts b/packages/runtime/src/metadataGeneration/tsoa.ts index 72c0087eb..ec5f951c2 100644 --- a/packages/runtime/src/metadataGeneration/tsoa.ts +++ b/packages/runtime/src/metadataGeneration/tsoa.ts @@ -1,3 +1,4 @@ +import multer from 'multer'; import { ExtensionType } from '../decorators/extension'; import type { Swagger } from '../swagger/swagger'; import { Validator } from '..'; @@ -17,6 +18,10 @@ export namespace Tsoa { produces?: string[]; } + export interface RegisterRoutesOptions { + multer?: multer.Multer; + } + export interface Method { extensions: Extension[]; deprecated?: boolean;