DocTreen
Adapters

Koa

Koa 2 with @koa/router.

const Koa    = require('koa');
const Router = require('@koa/router');
const { koaAdapter } = require('doctreen/koa');

const app    = new Koa();
const router = new Router();

router.get('/users', (ctx) => { ctx.body = []; });

// Can be called before or after routes
koaAdapter(router, { meta: { title: 'My API', version: '1.0.0' } });

app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000);

Mount order

Either order works. koaAdapter(router, ...) adds a GET route at docsPath to the @koa/router instance; on the first request, router.stack is read.

Runtime validation caveat

Same as Hono: when using validate: true, the adapter must be installed before your routes — Koa middleware does not retro-apply.

Schema resolution order

  1. defineRoute declaration
  2. JSDoc inside the handler function

On this page