AI-powered API Contract Factory + Full-stack Code Generation Engine
YApi Flow 将 YApi 从文档工具升维为研发流程的调度中心(Single Source of Truth)
中文文档 | Quick Start | Pipeline | Discussions
传统前端开发中,从接口文档到类型声明的过程是手动的、割裂的。YApi Flow 打通了这个链路:
传统方式:
PRD → 人工读 → 手写 Swagger → 人工导入 YApi → 手写 interface → 手写请求函数
YApi Flow:
PRD --[AI]--> Swagger --[CLI]--> YApi --[CLI]--> TypeScript / Java / Go
| Feature | swagger-typescript-api | yapi-to-typescript | orval | YApi Flow |
|---|---|---|---|---|
| Source | Swagger file | YApi | OpenAPI spec | PRD / NL / Swagger / YApi |
| AI Contract Gen | ❌ | ❌ | ❌ | ✅ |
| YApi Integration | ❌ | ✅ | ❌ | ✅ |
| TypeScript | ✅ | ✅ | ✅ | ✅ |
| Java (Spring Boot) | ❌ | ❌ | ❌ | ✅ |
| Go (Gin) | ❌ | ❌ | ❌ | ✅ |
| Node.js | ❌ | ❌ | ❌ | ✅ |
| MSW Mock | ❌ | ❌ | ✅ | ✅ |
| Zod Validation | ❌ | ❌ | ✅ | ✅ |
| Pipeline Mode | ❌ | ❌ | ❌ | ✅ |
# Install
npm install -g yapi-flow
# Initialize
yapi-flow init
# Set your YApi credentials in yapi-flow.config.ts, then:
yapi-flow generate在 AI 对话中直接操作 YApi,无需离开终端。
# 安装 skill 到 Claude Code
cp -r skills/yapi-flow ~/.claude/skills/yapi-flow之后直接在对话中说:
- "把 swagger.json 发布到 YApi"
- "从 YApi 项目生成 TypeScript 代码"
- "导出 YApi 接口文档"
- "检查 YApi 接口质量"
YApi Flow 的四阶段流水线:
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Stage 1 │ │ Stage 2 │ │ Stage 3 │ │ Stage 4 │
│ Contract │───>│ Publish │───>│ Frontend │───>│ Backend │
│ │ │ │ │ │ │ │
│ PRD/NL → │ │ Swagger → │ │ YApi → │ │ YApi → │
│ Swagger JSON│ │ YApi │ │ TypeScript │ │ Controller │
└──────────────┘ └──────────────┘ └──────────────┘ └──────────────┘
(AI) (CLI) (CLI) (CLI)
yapi-flow contract "用户签到接口,入参需要userId和签到类型..."yapi-flow publish ./swagger.json --merge goodyapi-flow generate --lang typescriptGenerates: types.ts (interfaces), client.ts (axios/fetch requests), mocks.ts (MSW handlers)
yapi-flow generate --lang java,goGenerates: Controllers, DTOs with validation, ready for business logic.
Input (YApi interface):
{
"path": "/api/user/sign-in",
"method": "POST",
"title": "用户签到"
}Output (types.ts):
/** 用户签到 */
export interface UserSignInRequest {
/** 用户ID */
userId: string
/** 签到类型 */
signType: 'NORMAL' | 'BONUS'
}
export interface UserSignInResponse {
points: number
streakDays: number
}Output (client.ts):
import { request } from '@/utils/request'
/** 用户签到 */
export async function userSignIn(data: UserSignInRequest): Promise<UserSignInResponse> {
return request({ url: '/api/user/sign-in', method: 'POST', data })
}// yapi-flow.config.ts
import { defineConfig } from 'yapi-flow'
export default defineConfig({
yapi: {
serverUrl: 'http://yapi.example.com',
token: process.env.YAPI_TOKEN!,
projectId: 123,
},
generate: {
outDir: './src/api/generated',
targets: [
{
language: 'typescript',
options: {
client: 'axios',
generateMSW: true,
generateZod: true,
importRequestFrom: '@/utils/request',
},
},
{
language: 'java',
options: {
framework: 'spring-boot',
packageName: 'com.example.api',
useLombok: true,
},
},
],
},
})| Command | Description |
|---|---|
yapi-flow init |
Initialize project config |
yapi-flow run |
Run full pipeline |
yapi-flow contract <input> |
Generate Swagger from PRD |
yapi-flow publish <file> |
Publish Swagger to YApi |
yapi-flow generate |
Generate code from YApi |
yapi-flow doctor |
Check environment |
yapi-flow config show |
View current config |
- Stage 2: YApi contract publishing
- Stage 3: TypeScript generation (interface + client + MSW + Zod)
- Stage 4: Java (Spring Boot), Go (Gin), Node.js (Express)
- Stage 1: AI-powered contract generation (GPT-4o / Claude)
- VS Code Extension
- Online Playground
- Feishu / Lark document parsing
- Custom template marketplace
See CONTRIBUTING.md. Contributions welcome!
MIT © duicym