Skip to content

Commit

Permalink
fix: missing optional file case in upload validate
Browse files Browse the repository at this point in the history
  • Loading branch information
jackey8616 committed Mar 13, 2024
1 parent de6b74d commit 41b1e48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export class ExpressTemplateService extends TemplateService<ExpressApiHandlerPar
const files = Object.values(args).filter(param => param.dataType === 'file');
if (param.dataType === 'file' && files.length > 0) {
const requestFiles = request.files as { [fileName: string]: Express.Multer.File[] };
if (requestFiles[name] === undefined) {
return undefined;
}

const fileArgs = this.validationService.ValidateParam(param, requestFiles[name], name, fieldErrors, undefined, this.minimalSwaggerConfig);
return fileArgs.length === 1 ? fileArgs[0] : fileArgs;
} else if (param.dataType === 'array' && param.array && param.array.dataType === 'file') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export class KoaTemplateService extends TemplateService<KoaApiHandlerParameters,
const files = Object.values(args).filter(param => param.dataType === 'file');
const contextRequest = context.request as any;
if (param.dataType === 'file' && files.length > 0) {
if (contextRequest.files[name] === undefined) {
return undefined;
}

const fileArgs = this.validationService.ValidateParam(param, contextRequest.files[name], name, errorFields, undefined, this.minimalSwaggerConfig);
return fileArgs.length === 1 ? fileArgs[0] : fileArgs;
} else if (param.dataType === 'array' && param.array && param.array.dataType === 'file') {
Expand Down

0 comments on commit 41b1e48

Please sign in to comment.