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 optionals 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 builder | Zod | |
|---|---|---|
| Used for docs / OpenAPI | Yes | Yes |
| Used for runtime validation | No (descriptive only) | Yes |
| Dependency | None | zod |
Refinements (.refine, .transform) | No | Yes |
Mixed routes work fine — only Zod schemas validate when validate: true;
s-builder routes pass through.