Postman Collection APIs to Swagger Docs

Being an back-end developer we generally works with APIs, for storing the APIs mostly developers are using the Postman, So in this blog will discuss how to covert postman collection APIs to swagger APIs documentation.

Express Js Project Convert Postman Collection APIs to Swagger Docs


Postman APIs Docs by Education Funda

Postman to Swagger Docs

Swagger-APIs by Education Funda


Step 1: You should have proper APIs postman collection for your project.

Step 2: Install swagger ui in your node project via ~ npm i swagger-ui-express.

Step 3: Put below code in your Routes index file OR app.js wherever you maintained your express routes as per your requirements:

Here you also need to create 1 json file for storing the details of your APIs docs just like we create swagger-output.json.

import express from "express";
import swaggerUi from "swagger-ui-express";

const swaggerDocument = JSON.parse(
await readFile(new URL("../../../../swagger-output.json", import.meta.url))
);

const router = express.Router();

// adding swagger docs routing
router.use("/docs", swaggerUi.serve);
router.get("/docs", swaggerUi.setup(swaggerDocument));

// routings
// ...

export default router;

Step 4: Now export your postman APIs collection in the json format.

Step 5: Go to website https://metamug.com/util/postman-to-swagger/.

Step 6: After converting your postman APIs collection to Swagger (Open API), and convert it into JSON format on any online YAML to JSON converter website then just copy all the JSON formatted code and paste in your swagger-output.json file.

Step 7: Now open http://localhost:[post]/docs, your docs will open with all the APIs which you stored in your postman collection. just like below:



That's it!
Congrats you reached the end of the document.

Check Author's Github Profile

<>Happy Coding</> 💻

Follow me here 💛


Comments

Popular posts from this blog

JavaScript Logical Output Based Interview Questions

Create and Deploy AWS SAM Application

Deploy Angular Build With Express JS Project