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

nextjs-swagger-gen

v1.0.10

Published

Generate OpenAPI Swagger specs from Next.js App Router API routes

Readme

nextjs-swagger-gen

Generate OpenAPI Swagger specs from Next.js App Router API routes. This tool automatically generates OpenAPI documentation from your Next.js API routes, including:

  • Route paths and methods
  • Query parameters
  • JSDoc comments and descriptions
  • Response types and descriptions

🎯 Features

  • 🔍 Automatic route detection
  • 📝 JSDoc comment parsing
  • 🔄 Query parameter extraction
  • 🎨 Interactive Swagger UI
  • 📦 Works with npx
  • 🔧 Configurable output and server options

📦 Installation

Using npx (Recommended)

npx nextjs-swagger-gen -a /path/to/your/app/folder -o /output/path/for/swagger.json

After running the command, open your browser and navigate to http://localhost:3333 to view your generated Swagger UI.

Global Installation

npm install -g nextjs-swagger-gen
nextjs-swagger-gen -a /path/to/your/app

Running from Repository

  1. Clone the repository:

    git clone https://github.com/youruser/nextjs-swagger-gen.git
    cd nextjs-swagger-gen
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build
  4. Run the tool:

    # Using npm script
    npm run start -- -a /path/to/your/app
    
    # Or directly with ts-node
    ts-node src/index.ts -a /path/to/your/app

🚀 Usage

npx nextjs-swagger-gen -a /path/to/your/app [options]

Options

  • -a, --app-path <path>: Path to your Next.js app directory (required)
  • -o, --output <path>: Path where to save the OpenAPI spec file (default: swagger-spec.json)
  • -p, --port <number>: Port to run the Swagger UI server (default: 3333)
  • -b, --base-url <url>: Base URL for the API (default: http://localhost:3000)
  • -s, --serve: Start the Swagger UI server after generating the spec (default: true)
  • -h, --help: Display help information
  • -V, --version: Display version information

Examples

Basic usage:

npx nextjs-swagger-gen -a ./my-nextjs-app

Custom output, port, and base URL:

npx nextjs-swagger-gen -a ./my-nextjs-app -o ./api-docs.json -p 8080 -b https://api.example.com

📝 JSDoc Support

The tool parses JSDoc comments to enhance the API documentation. Example:

/**
 * Get user's profile and activity data
 *
 * @route GET /api/users/[userId]/activity
 *
 * @param {NextRequest} request - The Next.js request object
 * @param {Object} params - Route parameters
 * @param {Promise<Object>} params.params - Dynamic route parameters
 * @param {string} params.params.userId - The unique identifier of the user
 *
 * @queryParam {string} timezone - User's timezone for activity timestamps (required)
 * @queryParam {string} period - Time period for activity data (e.g., 'day', 'week', 'month')
 * @queryParam {number} limit - Maximum number of activities to return (default: 10)
 *
 * @returns {Promise<NextResponse>} JSON response containing:
 *   - On success: {
 *       success: true,
 *       data: {
 *         userId: string,
 *         activities: Array<{
 *           id: string,
 *           type: string,
 *           timestamp: string,
 *           details: object
 *         }>,
 *         total: number
 *       }
 *     }
 *   - On error: { error: string } with appropriate status code
 *
 * @throws {Error} If there's an issue fetching the user's activity data
 */

This example shows:

  • Route parameters ([userId])
  • Required and optional query parameters
  • Detailed response structure
  • Error handling
  • Type information for parameters and responses

🤝 Contributing

Contributions are welcome! This project is specifically designed for Next.js App Router with TypeScript, but we're open to contributions that support other flavors or add new features.

Development Setup

  1. Fork the repository
  2. Clone your fork
  3. Install dependencies:
    npm install
  4. Make your changes
  5. Run tests (if available)
  6. Submit a pull request

Contributing Guidelines

  • Follow the existing code style
  • Add tests for new features
  • Update documentation as needed
  • Use conventional commits
  • Keep PRs focused and manageable

📄 License

MIT License - see the LICENSE file for details.

🙏 Acknowledgments