mock-cli: A Rust-Powered OpenAPI Mock Server That Starts in Milliseconds

Mock servers are a staple of frontend and integration development, but existing solutions often come with baggage: slow JVM warmup, Node module resolution, Docker requirements, or static stubs. mock-cli, written in Rust, aims to fix that with a single static binary that reads any OpenAPI 3 spec and serves dynamic, schema-compliant fake data.

Key Features

  • Native Rust binary: Cold starts in low milliseconds. No JVM, no Node overhead, no Docker pull.
  • Dynamic, schema-compliant data: Every request produces different fake data that still honors your schema. format: email gives a realistic email, format: uuid gives a v4 UUID, enum picks a valid value, required fields are always present, minItems/maxItems are respected.
  • Path-aware injection: If your route is /pets/{petId} and the response schema has a petId field, the value from the URL is injected into the response (coerced to the schema type). So GET /pets/123 returns {"petId": 123, ...}.
  • Cycle-safe $ref resolution: Recursive schemas are bounded to prevent stack overflow on self-referencing models.
  • Correct HTTP status codes: 200 on success, 404 for unknown paths, 405 for unsupported methods, 501 when no 200 response is defined.
  • All HTTP methods: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD, TRACE.
  • Cross-platform: macOS, Linux, Windows, x64 and arm64. Install via npm (auto-picks the right prebuilt binary) or grab the binary from GitHub Releases. Works offline.

Quick Demo

Drop a spec:

openapi: 3.0.3
info:
  title: Petstore
  version: 1.0.0
paths:
  /pets/{petId}:
    get:
      parameters:
        - name: petId
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  petId:
                    type: integer
                  name:
                    type: string
                  vaccinated:
                    type: boolean

Start the server:

mock-cli swagger.yaml
# ✓ Loaded "swagger.yaml" (1 paths)
# ✓ Listening on 127.0.0.1:3333

Hit it:

curl http://localhost:3333/pets/123
# {"petId":123,"name":"Dr. Margret Kihn","vaccinated":true}
curl http://localhost:3333/pets/456
# {"petId":456,"name":"Sarah Connor","vaccinated":false}

Notice petId echoes the path param, but name and vaccinated are fresh fake data on every call.

Why Rust?

The author chose Rust to ship a single static binary with no runtime dependency. The OpenAPI spec is a large tagged-union-shaped data model that maps cleanly onto Rust enums. The parsing and generation core (crates/core) has no IO — it's pure data transformation — making it trivial to test and reuse. The HTTP layer (crates/server) uses axum, and the CLI (crates/cli) uses clap. The project is split into three crates.

Roadmap

  • Done: dynamic mocking, path param injection, schema format/enum/required/array bounds, $ref resolution with cycle safety, correct HTTP status codes, configurable bind host, graceful shutdown.
  • Planned: hot reload on spec change, request validation against the spec, custom faker rules via config, multi-spec composition.

Installation

# npm (recommended — picks the right prebuilt binary for your platform)
npm install -g @mock-cli/server

# or build from source
cargo install --path crates/cli

# or just run it without installing
cargo run --release -- examples/swagger.yaml

What's Next?

Try it: npm install -g @mock-cli/server then mock-cli examples/swagger.yaml. The repo is at https://github.com/wanghao12345/mock-cli. The author is open to feedback on faker behavior (formats/enums) and priorities for hot-reload vs. request validation. Issue threads are open. MIT licensed, written in Rust 1.85+.