Skip to content

Commit

Permalink
added ability to pass multerInstance into generateRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
lalchan committed Oct 3, 2023
1 parent de210a8 commit f29665f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/cli/src/routeGeneration/templates/express.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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
Expand Down Expand Up @@ -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}}',
Expand Down
5 changes: 5 additions & 0 deletions packages/runtime/src/metadataGeneration/tsoa.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import multer from 'multer';
import { ExtensionType } from '../decorators/extension';
import type { Swagger } from '../swagger/swagger';
import { Validator } from '..';
Expand All @@ -17,6 +18,10 @@ export namespace Tsoa {
produces?: string[];
}

export interface RegisterRoutesOptions {
multer?: multer.Multer;
}

export interface Method {
extensions: Extension[];
deprecated?: boolean;
Expand Down

0 comments on commit f29665f

Please sign in to comment.