DocTreen

Schema builder

Lightweight `s` builder when you don't want a runtime schema library.

DocTreen ships a lightweight schema builder (s) for defining typed request and response shapes without a runtime schema library.

const { s } = require('doctreen');
// import { s } from 'doctreen';

s.string()            // { type: 'string' }
s.number()            // { type: 'number' }
s.boolean()           // { type: 'boolean' }
s.null()              // { type: 'null' }
s.unknown()           // { type: 'unknown' }

s.object({
  id:   s.number(),
  name: s.string(),
  bio:  s.optional(s.string()),   // optional field — shown with ? in the UI
})

s.array(s.string())
s.array(s.object({ id: s.number(), tag: s.string() }))

s.optional(s.string())  // wraps any node as optional

s is re-exported from all adapter packages for convenience:

const { s } = require('doctreen/express');
const { s } = require('doctreen/fastify');
const { s } = require('doctreen/hono');
const { s } = require('doctreen/koa');
const { s } = require('doctreen/nest');

Builder vs Zod

s builderZod
Used for docs / OpenAPIYesYes
Used for runtime validationNo (descriptive only)Yes
DependencyNonezod
Refinements (.refine, .transform)NoYes

Mixed routes work fine — only Zod schemas validate when validate: true; s-builder routes pass through.

On this page