I am trying to implement the swagger-autogen with the nodejs where my code in nodejs written in Immediately Invoked Function Expressions (IIFE) type.It is not giving the desired output. the swagger-output.json file is not having any api's.
Here is my app.js
const app = express();
app.use(helmet());
app.use(express.static(path.join(__dirname, "public")));
app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
require("./routes").connectRoutes(app);
app.listen(port, () => {
console.log("app listening on port " + port);
});
here is my routes.js
(() => {
function connectRoutes(app) {
app.enable("strict routing");
app.use(initialLogging);
app.use("/api/v1/", require("./route_handlers/auth"));
}
function initialLogging(req, res, next) {
var path = (req.method || "") + ":" + (req.originalUrl || "utils/error_utils");
const logger = require("./utils/logging_utils")(path);
logger.info("About to call");
next();
}
module.exports.connectRoutes = connectRoutes;
})();
I tried to implement the swagger-autogen but it is not giving any output.
i am using "swagger-autogen": "^2.23.5", express - "express": "^4.17.1",
my swagger.js file
const swaggerAutogen = require("swagger-autogen")();
const doc = {
info: {
title: appName,
description: appDesc,
},
host: "localhost:5001",
basePath: "/",
schemes: ["http", "https"],
consumes: ["application/json"],
produces: ["application/json"],
tags: [
{
name: appName,
description: appDesc,
},
],
};
let outputFile = "./public/api-docs/swagger-output1.json";
if (!fs.existsSync(outputFile)) {
outputFile = fs.openSync(outputFile, "w");
}
const endpointsFiles = ["./routes.js"];
swaggerAutogen(outputFile, endpointsFiles, doc);