My node application creates three different express servers, each one listening on a different port. Each server has a different set of APIs, with some in common between the three servers. There is also a swagger.yaml file that should contain documentation for any API to be routed. I would like to ensure that each API is documented in this swagger file before starting the application, and have it fail if any API is routed to a server but not documented.
So far, I have tried various middlewares to validate and route APIs based on the swagger document. However, as far as I have found, the validation functionality only checks the swagger file for any syntax or formatting mistakes, and the routing completely updates the app's routes based on swagger.yaml. I.e. the previous logic is removed. Example:
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() {
});
});
How do I keep the correct endpoints associated with app1, app2 and app3, but make sure they are in swagger.yaml?