问题描述
发生错误:
回调错误!抛向全局错误处理程序。 TypeError:无法 读取未定义的属性“ expressMiddleware” 在SwaggerRunner.create(/home/feel/cfeel-core/node_modules/feel-framework/src/modules/http_api/init_steps/bootstrap_swagger.js:318:33) 在/home/feel/cfeel-core/node_modules/swagger-node-runner/index.js:237:7
代码如下
/home/feel/cfeel-core/node_modules/feel-framework/src/modules/http_api/init_steps/bootstrap_swagger.js:318:33)
// Swagger express middleware
SwaggerRunner.create(swaggerConfig,(errors,runner) => {
if (errors) {
// Ignore unused deFinition warning
errors.validationWarnings = _.filter(
errors.validationWarnings,error => error.code !== 'UNUSED_DEFinitioN',);
// Some error occurred in configuring the swagger
if (!_.isEmpty(errors.validationErrors)) {
logger.error('Swagger Validation Errors:');
logger.error(errors.validationErrors);
}
if (!_.isEmpty(errors.validationWarnings)) {
logger.error('Swagger Validation Warnings:');
logger.error(errors.validationWarnings);
}
if (
!_.isEmpty(errors.validationErrors) ||
!_.isEmpty(errors.validationWarnings)
) {
cb(errors);
return;
}
}
// Swagger express middleware
const swaggerExpress = runner.expressMiddleware();//318:33
// Check the response and act appropriately on error
runner.on('responseValidationError',validationResponse => {
// Todo: Troubleshoot why default validation hook considers json response as string response
if (validationResponse.errors[0].code !== 'INVALID_RESPONSE_BODY') {
logger.error('Swagger Response Validation Errors:');
logger.error(validationResponse.errors[0].errors);
}
});
// Install middleware
swaggerExpress.register(app);
// To be used in test cases or getting configuration runtime
app.swaggerRunner = runner;
// Managing all the queries which were not caught by prevIoUs middlewares.
app.use((req,res,next) => {
// We need to check if the response is already handled by some other middlewares/fittings/controllers
// In case not,we consider it as 404 and send default response
// res.headeRSSent is a patch,and only works if above middlewares set some header no matter the status code
// Another possible workaround would be res.bodySize === 0
if (!res.headeRSSent) {
res.status(404);
res.json({ description: 'Page not found' });
}
next();
});
swaggerHelper
.getSchemaAsJSON()
.then(resolvedSchema => {
// Successfully mounted the swagger runner
cb(null,{
swaggerRunner: runner,deFinitions: resolvedSchema.deFinitions,});
})
.catch(reason => {
logger.error(reason.toString());
cb(reason);
});
});
}
/home/feel/cfeel-core/node_modules/swagger-node-runner/index.js:237:7
cb(null,self);
})
.catch(function(err) {
cb(err);//237:7
})
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)