@easydocs/nextjs
v0.10.1
Published
OpenAPI docs for Next.js (App + Pages Router), generated from real traffic. Local-first, self-hostable, open source.
Readme
@easydocs/nextjs
EasyDocs handler wrapper for Next.js App Router and Pages Router. Generate accurate OpenAPI 3.0 specs from your API's real traffic — local-first and self-hostable, with an offline mode (Ollama) where nothing leaves your machine.
Next.js middleware runs in the Edge runtime and cannot access response bodies. EasyDocs wraps individual route handlers instead — no URL changes needed.
Install
npm install @easydocs/nextjsApp Router
// app/api/users/route.ts
import { withEasydocs } from '@easydocs/nextjs'
import { NextResponse } from 'next/server'
export const GET = withEasydocs(async (req) => {
return NextResponse.json({ users: [] })
})
// with config
export const POST = withEasydocs(
async (req) => {
const body = await req.json()
return NextResponse.json({ created: true }, { status: 201 })
},
{ ai: { provider: 'anthropic' } }
)Dynamic routes expose params automatically:
// app/api/users/[id]/route.ts
export const GET = withEasydocs(async (req, { params }) => {
const { id } = await params
return NextResponse.json({ id })
})Pages Router
// pages/api/users.ts
import { withEasydocsPagesHandler } from '@easydocs/nextjs'
export default withEasydocsPagesHandler((req, res) => {
res.json({ users: [] })
})Configuration
withEasydocs(handler, {
ai: { provider: 'openai', model: 'gpt-4o' },
storage: { url: 'file:./docs.sqlite' },
capture: { ignoreRoutes: ['/api/health'] },
})View your docs
npm install -D @easydocs/dashboard
npx @easydocs/cli dashboard
# Or export to a file
npx @easydocs/cli export > openapi.jsonSee @easydocs/core for the full configuration reference.
