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

installOperationHandlers called upon each request for each path and method

Open einmalpizzafunghibitte opened this issue 3 years ago • 2 comments

Describe the bug installOperationHandlers seems to be called on every iteration of the request resolving. This seems to be a lot of overhead

To Reproduce I have implemented a custom resolver with the following signature which returns a resolve function: export function netControllerResolver(handlersPath: string, route: RouteMetadata, apiDoc: any) : express.RequestHandler

I have configured it like so ` this.app.use(OpenApiValidator.middleware({ apiSpec: self.schema,

  operationHandlers: {
    basePath: path.join(__dirname, 'netcontrollers'),
    resolver: netControllerResolver
  },

.... ` Run a request against one interface,

Actual behavior I noticed that it loops over all of the pathes whenever I do a request, e.g. doing a cat-POST request will loop over the cat-POST and the dog-GET request

Expected behavior Either:

  • The routes are resolved only once and remembered.
  • Only the relevant route gets resolved

einmalpizzafunghibitte avatar Jul 14 '22 07:07 einmalpizzafunghibitte

@einmalpizzafunghibitte I checked with resolver I've created and it works as expected: it is used only the first time and then, as it returns actual requestHandler and that handler is used after that.

In my case, resolver, being invoked only once, returns a closure as a request handler, and only that closure is called after that, theoretically, in IDE, that can look like entire resolver was called.

srgg avatar Sep 01 '22 02:09 srgg

I was wrong. It remembers the routes. But still it iterates over ALL routes immdediately that leads to me having an issue, if one of the routes defined in openapi, is not defined in code. Which is clearly an error when this route is called. But not when I call another route. In general this is something that one will notice in development. So this is not a really big deal. But maybe some room for improvement :) Thank you very much for your reply. And good job!

KlasikNormalBoy avatar Sep 15 '22 10:09 KlasikNormalBoy