我的节点应用程序创建三个不同的快速服务器,每个服务器都在另一个端口上侦听。每个服务器都有一组不同的API,三个服务器之间有一些共同点。还有一个swagger.yaml文件,其中应包含要路由的任何API的文档。我想确保在启动应用程序之前,每个API都记录在此swagger文件中,如果任何API路由到服务器但未记录,则会使其失败。
到目前为止,我已经尝试了各种中间件来根据swagger文档验证和路由API。但是,据我所知,验证功能仅检查swagger文件是否存在任何语法或格式错误,并且路由完全基于swagger.yaml更新应用程序的路由。即先前的逻辑被删除。示例:
let swagger = require('swagger-tools');
let YAML = require('yamljs');
let app1 = express();
let app2 = express();
let app3 = express();
//There is logic here that routes various endpoints to each app
let swaggerDocument = YAML.load("./swagger/swagger.yaml");
swagger.initializeMiddleware(swaggerDocument, function (middleware) {
app3.use(middleware.swaggerMetadata());
app3.use(middleware.swaggerValidator({
validateResponse: true
}));
app3.use(middleware.swaggerRouter({useStubs: true, contoller:
'/controllers'}));
app3.use(middleware.swaggerUi());
let server1 = http.createserver1(app1);
server1.listen(app1.get('port'), function() {
});
let server2 = http.createServer(app2);
server2.listen(app2.get('port'), function() {
});
let server3 = http.createServer(app3);
server3.listen(app3.get('port'), function() {
});
});
如何保持与app1,app2和app3关联的正确端点,但要确保它们位于swagger.yaml中?