There are not that many files present in the test folder to use for testing uploading files. Right now the same file is included multiple times, but the order is always different, so this should not matter.
The routeGenerator.ts now also adds two extra attributes to each file upload field, namely maxCount and multiple. The maxCount attribute is used by Multer to enforce only one file is uploaded to that field. However, HandleBars aims to be logic free, so a simple check (maxCount == 1) cannot be done in hapi.hbs to determine whether multiple files can be uploaded or not. Therefore, the multiple attribute is also added, but by design of the json function in Handlebars, this extra variable is also included in the Express and Koa routes.ts. Luckily, it does not do anything, but it is not very elegant. If there is a better way to do this, I would love to hear it!
Test plan
The unit tests that I added includes the case mentioned in the issue, but also two @UploadedFiles() statement to truly verify that these arrays are separated correctly.
The fix simply removes the upload.array() lines from any routes.ts files, because the same can be achieved by using upload.fields().
All Submissions:
Closing issues
Closes https://github.com/lukeautry/tsoa/issues/1619.
Potential Problems With The Approach
There are not that many files present in the test folder to use for testing uploading files. Right now the same file is included multiple times, but the order is always different, so this should not matter.
The
routeGenerator.ts
now also adds two extra attributes to each file upload field, namelymaxCount
andmultiple
. ThemaxCount
attribute is used by Multer to enforce only one file is uploaded to that field. However, HandleBars aims to be logic free, so a simple check (maxCount == 1
) cannot be done inhapi.hbs
to determine whether multiple files can be uploaded or not. Therefore, themultiple
attribute is also added, but by design of thejson
function in Handlebars, this extra variable is also included in the Express and Koaroutes.ts
. Luckily, it does not do anything, but it is not very elegant. If there is a better way to do this, I would love to hear it!Test plan
The unit tests that I added includes the case mentioned in the issue, but also two
@UploadedFiles()
statement to truly verify that these arrays are separated correctly.The fix simply removes the
upload.array()
lines from anyroutes.ts
files, because the same can be achieved by usingupload.fields()
.