api-mock-smart
v1.0.1
Published
Smart OpenAPI/Swagger-based mock API server with realistic data generation.
Maintainers
Readme
api-mock-smart
Smart OpenAPI/Swagger-based mock API server with intelligent data generation.
api-mock-smart reads your OpenAPI/Swagger 3 specification and spins up a mock API
server with realistic fake data, in‑memory persistence, and full CRUD endpoints.
📦 Installation
Install as a dev dependency (recommended):
npm install -D api-mock-smartOr install globally:
npm install -g api-mock-smartNode.js 18+ is required.
🚀 Quick Start
CLI
Start a mock server from an OpenAPI spec file:
npx api-mock-smart start ./openapi.yaml --port 3000Common options:
--port, -p: Port to run the server on (default:3000)--delay, -d: Fixed response delay in milliseconds (default:0)--watch, -w: Watch the spec file and reload on changes
Examples:
# Basic usage
api-mock-smart start ./api.yaml
# Custom port and delay
api-mock-smart start ./api.yaml --port 4000 --delay 200
# Watch mode for development
api-mock-smart start ./api.yaml --watch🧩 Programmatic Usage
Use api-mock-smart from your tests or Node.js app:
import { mockAPI } from "api-mock-smart";
const server = await mockAPI("./openapi.yaml", {
port: 3000,
delay: 100,
});
await server.start();
console.log("Mock server running on http://localhost:3000");
// Later...
await server.stop();Basic options:
port: Server port (default3000)delay: Fixed delay in ms (default0)
⚙️ Configuration (optional)
You can create an api-mock-smart.config.js file in your project root to customize
generators, delays, and error rates:
module.exports = {
generators: {
customerId: () => `CUST-${Math.random().toString(36).slice(2, 9)}`,
},
delay: { min: 100, max: 500 }, // variable delay
errorRate: 0.05, // 5% random error responses
};📝 License
MIT
