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

api-morph

v0.3.0

Published

A modern TypeScript-first OpenAPI document generator that analyzes your code and JSDoc comments to automatically generate comprehensive and accurate API documentation.

Readme

ci codecov npm version npm downloads license

一个现代化的 TypeScript 优先的 OpenAPI 文档生成器,通过分析代码和 JSDoc 注释自动生成全面、准确的 API 文档。

✨ 核心特性

  • 📝 JSDoc 驱动 - 使用熟悉的 JSDoc 语法描述 API,自动转换为 OpenAPI 3.1 文档
  • 🤖 智能分析 - 基于代码静态分析,自动推断 HTTP 方法、路径、参数等信息
  • 🎯 零侵入式 - 无需修改现有代码结构或添加装饰器,与现有项目完美融合
  • 🛡️ Zod 支持 - 原生支持 Zod Schema,享受类型安全的同时自动生成 JSON Schema
  • 🔌 多框架 - 支持 Express、Fastify、Koa 等主流 Node.js 框架
  • ⚙️ 可扩展 - 插件化架构支持自定义标签解析器和配置选项

🚀 快速开始

安装

npm install api-morph
# 或者
pnpm add api-morph
# 或者
yarn add api-morph

基本使用

1. 定义 Zod Schema

// schema.ts
import z from "zod/v4";

export const UserIdDto = z.object({
  id: z.string().meta({ description: "用户ID" }),
});

export const UpdateUserDto = z.object({
  email: z.email().meta({
    description: "用户邮箱地址",
    examples: ["[email protected]"],
  }),
  username: z.string().min(3).max(50).meta({
    description: "用户名",
    examples: ["John Doe"],
  }),
});

export const UpdateUserVo = z.object({
  id: z.string().meta({ description: "用户ID" }),
  email: z.email().meta({
    description: "用户邮箱地址",
    examples: ["[email protected]"],
  }),
  username: z.string().min(3).max(50).meta({
    description: "用户名",
    examples: ["John Doe"],
  }),
});

2. 创建 Express 应用

// index.ts
import {
  generateDocument,
  generateSwaggerUI,
  getSwaggerUIAssetInfo,
  zodValidator,
} from "api-morph";
import express from "express";
import { UpdateUserDto, UpdateUserVo, UserIdDto } from "./schema";

const app = express();
app.use(express.json());

// 提供 Swagger UI 静态资源
app.use(express.static(getSwaggerUIAssetInfo().assetPath));

/**
 * @summary 更新用户信息
 * @description 更新指定用户的个人信息
 * @tags users
 * @response 200 {@link UpdateUserVo} 更新用户信息成功
 */
app.put(
  "/api/users/:id",
  zodValidator({ params: UserIdDto, body: UpdateUserDto }),
  (req, res) => {
    const { id } = req.params;
    const { email, username } = req.body;

    res.json({ id, email, username });
  }
);

// 生成 OpenAPI 文档
const openapi = await generateDocument({
  info: {
    version: "1.0.0",
    title: "用户管理 API",
    description: "这是一个用户管理 API 的文档示例",
  },
});

// 提供 OpenAPI JSON 和 Swagger UI
app.get("/openapi.json", (req, res) => res.json(openapi));
app.get("/swagger-ui", (req, res) => {
  res.send(generateSwaggerUI({ url: "/openapi.json" }));
});

app.listen(3000, () => {
  console.log("访问 http://localhost:3000/swagger-ui 查看 API 文档");
});

📖 文档

完整的文档和 API 参考请访问我们的官方文档站点

🔧 支持的框架

  • ✅ Express
  • ✅ Fastify(即将支持)
  • ✅ Koa(即将支持)
  • ✅ NestJS(即将支持)

📄 许可证

本项目基于 MIT 许可证开源。