<reponame>tilleps/devstack<filename>lib/middlewares/swagger/validator.js
/**
 * 
 * @see https://www.reddit.com/r/node/comments/26f3ld/express_middleware_with_async_initialization/
 * 
 * 
 * var swaggerTools = require('swagger-tools');
 * var promise = new Promise(function (resolve, reject) {
 * 
 *   swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
 *     resolve(middleware);  
 *   });
 * 
 * });
 * 
 * var options = {};
 * app.use(thisMiddleware(promise, options));
 * 
 * @author <NAME> <<EMAIL>>
 */


module.exports = function (promise, options) {
  
  return function (req, res, next) {
    promise
    .then(function (middleware) {
      middleware.swaggerValidator(options)(req, res, next);
    })
    .catch(function (err) {
      next(err);
    });
    
  };
  
};

