Adapters
Fastify
Fastify 4 and 5 — captures every route via the onRoute hook.
const fastify = require('fastify')();
const { fastifyAdapter } = require('doctreen/fastify');
// Call BEFORE registering routes — uses the onRoute hook
fastifyAdapter(fastify, {
meta: { title: 'My API', version: '1.0.0' },
});
fastify.get('/users', async (req, reply) => reply.send([]));
fastify.listen({ port: 3000 });Mount order
Call fastifyAdapter before registering routes. The adapter installs an
onRoute hook; routes added after the hook are captured at registration time
— no traffic needed.
Fastify native JSON Schema
If you already annotate routes with Fastify's built-in schema option,
DocTreen reads it automatically — no defineRoute needed:
fastify.get('/users/:id', {
schema: {
description: 'Get a user by ID',
response: {
200: {
type: 'object',
properties: {
id: { type: 'number' },
name: { type: 'string' },
email: { type: 'string' },
},
},
},
},
handler: async (req, reply) => { /* ... */ },
});Schema resolution order
defineRoutedeclaration- Fastify native JSON Schema (
schemaoption) - JSDoc inside the handler function