npx doctreen mock — spec-driven fake API with CRUD short-circuits.
v1.12
Spin up an Express-backed fake of your API in seconds — no spec stitching, no
manual handler stubs. doctreen mock reads any OpenAPI 3.x document (from a
live /docs URL or a local JSON file) and synthesises responses from each
operation's schema.
# From a running doctreen-enabled servernpx doctreen mock --from http://localhost:3000/docs --port 4000# From an OpenAPI file on disknpx doctreen mock --from ./openapi.json --port 4000# With latency + random error injection (shake out frontend error paths)npx doctreen mock --from ./openapi.json --latency 100-500 --error-rate 0.1
Schema-faithful responses generated from each operation's success response. $ref, oneOf/anyOf/allOf, enum, const, default, and per-operation examples are all respected.
CRUD short-circuits. When the spec exposes /resource + /resource/:id, POST actually creates a row in an in-memory store, GET reads it back, PATCH/PUT mutate it, DELETE removes it. Envelope responses ({ products: [...], total, filters }) are detected and the array is swapped in.
Realistic values via Faker(optional). Install @faker-js/faker and fields named email, name, uuid, createdAt, … plus OpenAPI formats (uuid, email, date-time, uri, ipv4, …) get realistic values. Without it, output falls back to deterministic placeholders.
Latency + error injection.--latency 200 for a fixed delay, --latency 100-500 for a random range. --error-rate 0.1 returns a randomly-picked declared 4xx/5xx response 10 % of the time.
Optional persistence.--persist ./fixtures.json writes the in-memory store to disk on every mutation and loads it on restart.