Skip to content

Commit

Permalink
Reorder upload and security middlewares (#866)
Browse files Browse the repository at this point in the history
- Move multipart middleware after security middleware so that security
  handlers can abort request pipeline before uploads are processed.

Fixes #865
  • Loading branch information
mdmower authored Nov 12, 2023
1 parent f732379 commit 95543d6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/openapi.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,6 @@ export class OpenApiValidator {
.catch(next);
});

if (this.options.fileUploader) {
// multipart middleware
let fumw;
middlewares.push(function multipartMiddleware(req, res, next) {
return pContext
.then(({ context: { apiDoc } }) => {
fumw = fumw || self.multipartMiddleware(apiDoc);
return fumw(req, res, next);
})
.catch(next);
});
}

// security middlware
let scmw;
middlewares.push(function securityMiddleware(req, res, next) {
Expand All @@ -184,6 +171,19 @@ export class OpenApiValidator {
.catch(next);
});

if (this.options.fileUploader) {
// multipart middleware
let fumw;
middlewares.push(function multipartMiddleware(req, res, next) {
return pContext
.then(({ context: { apiDoc } }) => {
fumw = fumw || self.multipartMiddleware(apiDoc);
return fumw(req, res, next);
})
.catch(next);
});
}

// request middlweare
if (this.options.validateRequests) {
let reqmw;
Expand Down

0 comments on commit 95543d6

Please sign in to comment.