Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: download swagger docs as json #391

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ requests.rest
package-lock.json
docker-compose.yml
package-lock.json

swagger.json
27 changes: 27 additions & 0 deletions src/bk/mail.ts.bk
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import nodemailer from "nodemailer";
import config from "../config";
import { BadRequest } from "../middleware";

const Sendmail = async (emailcontent: any) => {
const transporter = nodemailer.createTransport({
// service: config.SMTP_SERVICE,
// host: "smtp.gmail.com",
// port: 587,
host: config.SMTP_HOST,
port: Number(config.SMTP_PORT),
// secure: false,
auth: {
user: config.SMTP_USER,
pass: config.SMTP_PASSWORD,
},
});
try {
await transporter.sendMail(emailcontent);
return "Email sent successfully.";
} catch (error) {
console.log(error);
throw new BadRequest("Error sending email");
}
};

export { Sendmail };
16 changes: 16 additions & 0 deletions src/controllers/docsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Request, Response } from "express";
import { swaggerSpecsContent } from "../swaggerConfig";

class DocsController {
async downloadApiDocs(req: Request, res: Response) {
console.log("**** the code is here to download ****");
res.setHeader(
"Content-Disposition",
"attachment; filename=swagger-specs.json",
);
res.setHeader("Content-Type", "application/json");
res.send(swaggerSpecsContent);
}
}

export default DocsController;
45 changes: 23 additions & 22 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
// src/index.ts
import "reflect-metadata";
import AppDataSource from "./data-source";
import log from "./utils/logger";
import cors from "cors";
import dotenv from "dotenv";
import express, { Express, Request, Response } from "express";
import "reflect-metadata";
import swaggerUi from "swagger-ui-express";
import config from "./config";
import dotenv from "dotenv";
import cors from "cors";
import passport from "./config/google.passport.config";
import AppDataSource from "./data-source";
import { errorHandler, routeNotFound } from "./middleware";
import {
userRouter,
adminRouter,
authRoute,
helpRouter,
testimonialRoute,
notificationRouter,
productRouter,
jobRouter,
blogRouter,
adminRouter,
exportRouter,
sendEmailRoute,
paymentRouter,
contactRouter,
docsRouter,
exportRouter,
faqRouter,
helpRouter,
jobRouter,
notificationRouter,
paymentFlutterwaveRouter,
paymentRouter,
paymentStripeRouter,
faqRouter,
productRouter,
sendEmailRoute,
testimonialRoute,
userRouter,
} from "./routes";
import { smsRouter } from "./routes/sms";
import { routeNotFound, errorHandler } from "./middleware";
import { orgRouter } from "./routes/organisation";
import swaggerUi from "swagger-ui-express";
import swaggerSpec from "./swaggerConfig";
import { smsRouter } from "./routes/sms";
import updateRouter from "./routes/updateOrg";
import swaggerSpec from "./swaggerConfig";
import { Limiter } from "./utils";
import log from "./utils/logger";
import ServerAdapter from "./views/bull-board";
import passport from "./config/google.passport.config";
dotenv.config();

const port = config.port;
Expand Down Expand Up @@ -84,7 +85,7 @@ server.use("/api/v1", faqRouter);

server.use("/api/v1/queues", ServerAdapter.getRouter());
server.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));

server.use("/api/v1/docs", docsRouter);
server.use(routeNotFound);
server.use(errorHandler);

Expand Down
9 changes: 9 additions & 0 deletions src/routes/docs.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Router } from "express";
import DocsController from "../controllers/docsController";

const docsRouter = Router();
const docsController = new DocsController();

docsRouter.get("/download", docsController.downloadApiDocs);

export { docsRouter };
9 changes: 5 additions & 4 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
export * from "./auth";
export * from "./admin";
export * from "./auth";
export * from "./blog";
export * from "./contactRoutes";
export * from "./docs.routes";
export * from "./export";
export * from "./help-center";
export * from "./job";
export * from "./organisation";
export * from "./notificationsettings";
export * from "./paymentStripe";
export * from "./paymentLemonSqueezy";
export * from "./organisation";
export * from "./payment";
export * from "./paymentLemonSqueezy";
export * from "./paymentStripe";
export * from "./product";
export * from "./sendEmail.route";
export * from "./sms";
Expand Down
4 changes: 4 additions & 0 deletions src/swaggerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from "fs";
import swaggerJsdoc, { SwaggerDefinition } from "swagger-jsdoc";
import { version } from "../package.json";
import config from "./config";
Expand Down Expand Up @@ -47,5 +48,8 @@ const options = {
};

const specs = swaggerJsdoc(options);
fs.writeFileSync("./swagger.json", JSON.stringify(specs, null, 2));
const swaggerSpecsContent = JSON.stringify(specs, null, 2);

export { swaggerSpecsContent };
export default specs;
Empty file.
Loading