title: How to install Express middleware (express-openapi-validator) in NestJS?
body: <p>I am writing a <a href="https://nestjs.com/" rel="nofollow noreferrer">NestJS</a> application. Now I want to install the <a href="https://expressjs.com/" rel="nofollow noreferrer">Express</a> middleware <a href="https://github.com/cdimascio/express-openapi-validator" rel="nofollow noreferrer">express-openapi-validator</a>.</p>
  <p>However, I can't get it to work. There is a <a href="https://github.com/cdimascio/express-openapi-validator#usage" rel="nofollow noreferrer">description for how to install the express-openapi-validator in express</a>, but it always results in errors.</p>
  <p>For example</p>
  <pre><code>export class AppModule implements NestModule {
      configure(consumer: MiddlewareConsumer) {
          consumer.apply(middleware({apiSpec &quot;./bff-api.yaml&quot;}))
              .forRoutes(OrganizationController)
      }
  }
  </code></pre>
  <p>results in</p>
  <pre><code>error TS2345: Argument of type 'OpenApiRequestHandler[]' is not assignable to parameter of type 'Function | Type&lt;any&gt;'.
        Type 'OpenApiRequestHandler[]' is missing the following properties from type 'Type&lt;any&gt;': apply, call, bind, prototype, and 4 more.
  </code></pre>
  <p>How can I install this middleware in NestJS?</p>