-
-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subsequent express middleware not invoked after OpenApiValidator #908
Comments
I'm experiencing the same issue. It seems like it never attempts to resolve routes for subsequently defined middlewares. In my case, all of my spec files use the same root server path (https://server.com/api), and it happens regardless of how I have a hunch that a wildcard route for the API base url is created ( like /api/*) with a catch-all error handler at the end, that could essentially swallowing all subsequently defined routes to /api/*. I haven't looked at the source yet so this is just a hunch. UPDATE: |
@dieseldjango if you need subsequent middleware to run, you need to make sure you return a valid express That means your For example, request handlers should operate like this: openApiHandlers.moduleName.funcName = function handler(req, res, next){
console.log('Handling the operation')
next() <- this is what will forward the request to the next middleware
} I assume that in the case of an For example: ...
if (!mod) {
// return a valid request handler
return (req, res, next) => {
// Create your error without throwing it
const error = new InternalServerError(
`Could not find handler module "${moduleName}" for method "${route.method}" of route "${route.openApiRoute}"`
)
next(error) // call the next(), passing the error as the argument
}
}
const func = mod[functionName];
if (func === undefined) {
// return a valid request handler
return (req, res, next) => {
// Create your error without throwing it
const error = new Error(`Could not find function "${functionName}" in module "${moduleName}"`);
next(error) // call the next(), passing the error as the argument
}
}
... Now calls to invalid handlers will resolve successfully with a handler that passes an error along to the next middleware. This pattern or may not be ideal. I'd think that in most cases it would better for unresolved handlers to immediately fail catastrophically rather than silently passing an error along. |
Thanks. I'll make sure to call |
Describe the bug
I have an express server that is configured with multiple middleware, including some before the openapi validator and some after, such as:
When running the app the middleware registered after my OpenApiValidator instance is never getting called.
Is this to be expected? I was expecting that the validator would register express routes and would otherwise just call the next middleware in the chain.
To Reproduce
Setup as described below, write to console or set a breakpoint in
someOtherMiddleware
, start your server, send a request to one of the openapi endpoints.Actual behavior
The
someOtherMiddleware
function is not called.Expected behavior
The
someOtherMiddleware
function should be called.Examples and context
Here's an example of what the config is like:
The text was updated successfully, but these errors were encountered: