npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bernierllc/nextjs-openapi

v0.3.2

Published

Next.js-specific OpenAPI generation with App Router and Pages Router support

Readme

@bernierllc/nextjs-openapi

Next.js-specific OpenAPI generation with App Router and Pages Router support.

Features

  • Dual Router Support: Full support for both App Router (app/) and Pages Router (pages/)
  • Automatic Discovery: Discovers API routes in your Next.js project
  • Metadata Extraction: Extracts JSDoc annotations, Zod schemas, and Next.js runtime config
  • File Watching: Development mode with hot reload
  • TypeScript First: Full TypeScript support with strict typing
  • NeverHub Integration: Optional real-time event publishing

Installation

npm install @bernierllc/nextjs-openapi

Usage

Basic Setup

import { NextJSOpenAPIGenerator } from '@bernierllc/nextjs-openapi';

const generator = new NextJSOpenAPIGenerator({
  projectRoot: './my-nextjs-app',
  appDir: 'app',
  pagesDir: 'pages',
  sources: {
    jsdoc: {
      enabled: true,
      patterns: ['**/*.ts', '**/*.tsx'],
      includeMiddleware: true
    },
    metadata: {
      enabled: true,
      includeRuntime: true
    }
  },
  output: {
    json: 'public/openapi.json',
    yaml: 'public/openapi.yaml'
  }
});

// Generate OpenAPI specification
const result = await generator.generate();
console.log('Generated spec:', result.spec);

App Router Example

// app/api/users/route.ts

/**
 * @openapi
 * /api/users:
 *   get:
 *     summary: List all users
 *     description: Retrieve a list of all users
 */
export async function GET() {
  return Response.json({ users: [] });
}

/**
 * @openapi
 * /api/users:
 *   post:
 *     summary: Create a user
 *     description: Create a new user
 */
export async function POST() {
  return Response.json({ id: '1' });
}

export const runtime = 'edge';
export const dynamic = 'force-dynamic';

Pages Router Example

// pages/api/products.ts

/**
 * @openapi
 * /api/products:
 *   get:
 *     summary: List all products
 *     description: Retrieve a list of all products
 */
export default function handler(req, res) {
  if (req.method === 'GET') {
    return res.json({ products: [] });
  }
  return res.status(405).end();
}

Dynamic Routes

Both App Router and Pages Router dynamic segments are automatically converted to OpenAPI path parameters:

// app/api/users/[id]/route.ts
// Generates: /api/users/{id}

export async function GET(request: Request, { params }: { params: { id: string } }) {
  return Response.json({ id: params.id });
}

Watch Mode

const watcher = generator.watch((result) => {
  console.log('OpenAPI updated:', result.spec.info);
  console.log('Routes:', Object.keys(result.spec.paths));
});

// Later...
watcher.stop();

Discover Routes Only

// Discover all API routes
const allRoutes = await generator.discoverAPIRoutes();

// Discover App Router routes only
const appRoutes = await generator.discoverAppRoutes();

// Discover Pages Router routes only
const pagesRoutes = await generator.discoverPagesRoutes();

Configuration

NextJSOpenAPIConfig

interface NextJSOpenAPIConfig {
  projectRoot: string;              // Next.js project root
  appDir?: string;                  // App Router directory (default: 'app')
  pagesDir?: string;                // Pages Router directory (default: 'pages')
  sources: NextJSSourceConfig;      // Documentation sources
  output: NextJSOutputConfig;       // Output configuration
  development?: NextJSDevelopmentConfig;  // Dev options
  build?: NextJSBuildConfig;        // Build options
}

Source Configuration

interface NextJSSourceConfig {
  jsdoc?: {
    enabled: boolean;
    patterns: string[];              // File patterns to scan
    includeMiddleware?: boolean;     // Include middleware docs
  };
  zod?: {
    enabled: boolean;
    schemasPath: string;            // Zod schemas directory
    metadataPattern: string;        // Metadata export pattern
  };
  metadata?: {
    enabled: boolean;
    includeRuntime?: boolean;       // Include runtime config
    includePerformance?: boolean;   // Include performance hints
  };
}

Runtime Configuration Support

The generator automatically extracts Next.js runtime configuration:

export const runtime = 'edge';              // Runtime mode
export const dynamic = 'force-dynamic';     // Dynamic behavior
export const revalidate = 60;               // Revalidation period

API

generate(): Promise<NextJSGenerationResult>

Generate complete OpenAPI specification.

discoverAPIRoutes(): Promise<NextJSAPIRoute[]>

Discover all API routes (both App Router and Pages Router).

discoverAppRoutes(): Promise<NextJSAppRoute[]>

Discover App Router routes only.

discoverPagesRoutes(): Promise<NextJSPagesRoute[]>

Discover Pages Router routes only.

extractRouteMetadata(route): Promise<NextJSRouteMetadata>

Extract metadata from a specific route.

watch(callback): NextJSWatcher

Watch for file changes and regenerate on changes.

watchAPIRoutes(callback): NextJSWatcher

Watch API routes only.

Dependencies

  • @bernierllc/openapi-generator - Core OpenAPI generation
  • @bernierllc/route-discoverer - Route discovery
  • @bernierllc/jsdoc-openapi-parser - JSDoc parsing
  • @bernierllc/zod-openapi-converter - Zod schema conversion
  • @bernierllc/file-handler - File operations
  • @bernierllc/logger - Logging
  • @bernierllc/neverhub-adapter - Event publishing
  • chokidar - File watching

License

Copyright (c) 2025 Bernier LLC. See LICENSE file for details.