-
Notifications
You must be signed in to change notification settings - Fork 50
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
Using predefined express app object #35
Comments
you may add the validator inside osa module. |
In order to add additional middleware before the validation middleware, I have done something similar to what you described. Take a look at the dist/middleware/express.app.config.js file. This is where middleware is added to the app object. I simply added my own parameter to the options object, then modified express.app.config.js to add additional middleware. For example in index.js: var options = { openApiValidator: { ... }, routing: { controllers: path.join(__dirname, './controllers'), }, preValidationMiddleware: [ function(req, res, next) { // do something }, function(req, res, next) { // do something else } ] } Then in express.app.config.js you can access the new parameter in the constructor via the appOptions argument: class ExpressAppConfig { constructor(definitionPath, appOptions) { .... this.app.use(cookieParser()); // set additional middleware this.setPreValidationMiddleware(appOptions); const swaggerUi = new swagger_ui_1.SwaggerUI(swaggerDoc, appOptions.swaggerUI); this.app.use(swaggerUi.serveStaticContent()); this.app.use(OpenApiValidator.middleware(this.openApiValidatorOptions)); ..... } setPreValidationMiddleware(appOptions) { if('preValidationMiddleware' in appOptions) { appOptions.preValidationMiddleware.forEach(middleware => { this.app.use(middleware); }); } } This approach does require forking so your modifications don't get clobbered anytime you rebuild the dependencies. However, it's not to difficult to configure. |
+1 |
I would like to fiddle around with the app object to add middleware to be called before the swagger stuff.
But as the express app object is created within the oas3 module I could only add at the end of the process queue which will not work.
How can I either define my own app object and feed it to the oas3 middleware constructor or add some definition to get to this goal?
PS: I would also try to just fork the module but nodejs module handling is all new to me, so that is too much work for the moment. I cannot even rebuild the unchanged module by now. A how-to-hack this module doc would be great too.
The text was updated successfully, but these errors were encountered: