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 🙏

© 2025 – Pkg Stats / Ryan Hefner

s2r

v0.1.25

Published

Generate TypeScript API clients from Swagger/OpenAPI 2.0-3.1 documents with built-in axios, mock server, and AI-friendly documentation - S2R (Swagger to Request)

Readme

S2R

从 Swagger/OpenAPI 文档自动生成 TypeScript API 客户端代码,支持 Mock 服务和 AI 文档转换。

安装

npm install -g s2r

基本使用

生成 API 客户端

# 从文件生成
s2r generate ./swagger.json --output ./src/api

# 从 URL 生成
s2r generate https://api.example.com/swagger.json --output ./src/api

使用生成的代码

import { apiUsersGet, apiUsersPost } from './src/api';

// 调用 API
const users = await apiUsersGet({ page: 1, limit: 10 });
const newUser = await apiUsersPost({ name: 'John', email: '[email protected]' });

拦截器系统

import { InterceptorManager, createAuthInterceptor } from 's2r';
import axios from 'axios';

const axiosInstance = axios.create();
const interceptorManager = new InterceptorManager(axiosInstance);

// 添加认证拦截器
interceptorManager.register({
  request: [createAuthInterceptor({ type: 'bearer', token: 'your-token' })]
});

启动 Mock 服务

s2r mock ./swagger.json --port 3001

访问 http://localhost:3001/docs 查看 Swagger UI。

生成 AI 文档

s2r ai-docs ./swagger.json --output ./docs/api.md

配置文件

创建 s2r.config.js

module.exports = {
  swagger: {
    source: './swagger.json'
  },
  generation: {
    outputDir: './src/api',
    typescript: true
  },
  runtime: {
    baseURL: 'https://api.example.com',
    timeout: 10000
  }
};

命令行选项

# 生成代码
s2r generate <source> [options]
  --output, -o     输出目录
  --config, -c     配置文件路径

# Mock 服务
s2r mock <source> [options]
  --port, -p       端口号 (默认: 3001)
  --no-ui          禁用 Swagger UI (默认启用)

# AI 文档
s2r ai-docs <source> [options]
  --output, -o     输出文件路径
  --format, -f     输出格式 (markdown|json|yaml|llm)
  --preset, -p     预设配置 (developer|reference|training|preview|llm)

# 验证文档
s2r validate <source> [options]
  --verbose, -v    显示详细验证结果

# 发布 NPM 包
s2r publish <source> [options]
  --name, -n       包名
  --version, -v    版本号

许可证

MIT License