express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

Call express-openapi-validator inside another middleware.

Open rupeshmore opened this issue 3 years ago • 0 comments

Call express-openapi-validator from another middleware.

When I configure express-openapi-validator as a call within another middleware. For example:

const myMiddleware = (req, res, next) => {
    try {
        OpenApiValidator.middleware({
            apiSpec: './openapi.yaml',
            validateRequests: true,
            validateResponses: true,
        }).map(m =>m(req, res, next)) // since it returns a OpenApiRequestHandler[]
    } catch (err) {
        next(err);
    }
};

However the error is not passed to the next middleware and it is only printed to the console.

How to fix the above to call the validator inside another middleware?

rupeshmore avatar Jun 14 '22 11:06 rupeshmore