v1.12 — spec-driven mock serverOne Zod schema per route.
One Zod schema per route.
Docs, tests, and runtime validation.
DocTreen is a code-first API documentation library for Node.js. Define your route shape once and get an interactive docs UI, OpenAPI 3.1 export, runnable integration flows, and 422-on-invalid-request validation — for Express, Fastify, Hono, Koa, and NestJS.
npm install doctreen
import express from 'express';
import { z } from 'zod';
import { expressAdapter, defineRoute } from 'doctreen/express';
const app = express();
app.use(express.json());
app.post('/users', defineRoute(
(req, res) => res.status(201).json({ id: 1, ...req.body }),
{
description: 'Create a user',
request: { body: z.object({ name: z.string(), email: z.string().email() }) },
response: z.object({ id: z.number(), name: z.string(), email: z.string() }),
errors: { 409: 'Email already in use' },
}
));
// Mount docs UI + OpenAPI 3.1 + runtime validation in one place.
app.use(expressAdapter(app, {
meta: { title: 'My API', version: '1.0.0' },
validate: true,
}));- Interactive docs UI at /docs — zero-dependency HTML
- OpenAPI 3.1 export with $ref dedup, tags, callbacks, webhooks
- Runtime validation: same Zod schema returns a structured 422
- Schema drift detection against live traffic, CI-ready
- Spec-driven mock server: npx doctreen mock --from <url|file>
- Postman Collection v2.1 export + runnable integration flows
Works with your stack
- Express
- Fastify
- Hono
- Koa
- NestJS
Drop it next to your existing router.
No router rewrite, no separate spec file, no decorator boilerplate.