## 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):

```bash
npm install -D api-mock-smart
```

Or install globally:

```bash
npm install -g api-mock-smart
```

Node.js **18+** is required.

---

## 🚀 Quick Start

### CLI

Start a mock server from an OpenAPI spec file:

```bash
npx api-mock-smart start ./openapi.yaml --port 3000
```

Common 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:

```bash
# 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:

```javascript
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 (default `3000`)
- **`delay`**: Fixed delay in ms (default `0`)

---

## ⚙️ Configuration (optional)

You can create an `api-mock-smart.config.js` file in your project root to customize
generators, delays, and error rates:

```javascript
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


