DEV Community

rahman orewole
rahman orewole

Posted on

Effortless API Documentation with Maira-CLI: Generate Swagger Docs on the Fly

Documenting APIs is often tedious, but what if you could generate detailed Swagger documentation automatically while testing your API? That's exactly what Maira-CLI does. This developer tool intercepts requests and responses to create accurate API documentation without additional effort.
Getting Started with Maira-CLI
Step 1: Install Maira-CLI
First, install Maira-CLI globally on your system using npm:
npm install -g maira-cli
Step 2: Start the Proxy Server
Run the proxy inside the backend project you want to document. Replace values as needed:
maira-cli http --port=3000 --project=userDoc --baseurl=http://localhost:3000
--port=3000: The port your backend server is running on.
--project=userDoc: The name of the documentation folder.
--baseurl=http://localhost:3000: The base URL of your API.

Step 3: Configure Routes and Authentication
After running the command, Maira-CLI creates a folder: /maira_docs/userDoc/. Inside, you'll find:
config.json: Define project details, routes to document, and authentication headers.
paths.json: Stores detected API paths and request details.

Example config.json
{
"title": "User Documentation",
"version": "1.0.0",
"serverUrls": ["http://localhost:3000"],
"routes": [
"/ping/pong",
"/ping",
"/ping/:id"
],
"security": {
"apiKey": ["x-api-key", "x-api-user"],
"http": ["authorization"]
}
}

Once configured, make API requests through the proxy (http://localhost:8081) just as you would normally.
Step 4: Generating Documentation
Maira-CLI generates a swagger_template.json file based on config.json. After making requests, run:
maira-cli generate -c=./maira_docs/userDoc/swagger_template.json -p=./maira_docs/userDoc/paths.json -o=./maira_docs/userDoc/docs -n=user-docs.json
Step 5: Viewing Your Documentation
Once generation is complete, you'll receive a preview link, like:
https://maira-virid.vercel.app/?id=uuid
This link allows you to share and view your API documentation effortlessly.
Why Use Maira-CLI?
✅ No manual Swagger setup - Everything is automatically generated while you test your API. ✅ Captures request & response data - Ensures accurate documentation. ✅ Supports authentication headers - Securely documents API access methods. ✅ Easy preview & sharing - Get a hosted link to your generated docs.
Maira-CLI makes API documentation simple and efficient. Try it today! 🚀

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

If you found this post helpful, please leave a ❤️ or a friendly comment below!

Okay