Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>LeebApi - Swagger to TypeScript/JavaScriptNew to Visual Studio Code? Get it now.
LeebApi - Swagger to TypeScript/JavaScript

LeebApi - Swagger to TypeScript/JavaScript

leeb

| (0) | Free
根据 Swagger 文档自动生成 TypeScript/JavaScript 类型定义和接口请求配置
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

LeebApi - Swagger to TS/JS

根据 Swagger / OpenAPI 文档自动生成 TypeScript 或 JavaScript 代码。

功能特性

  • 🎨 左侧面板交互 — 点击活动栏图标打开可视化生成面板
  • 🔗 支持 URL + JSON — 可从 Swagger 地址拉取,或直接粘贴 JSON
  • 📝 双语言输出 — TypeScript(带类型) / JavaScript(带 JSDoc)
  • 📁 双文件生成 —
    • {前缀}.types.ts / {前缀}.types.js — 实体类型定义
    • {前缀}.api.ts / {前缀}.api.js — 接口请求方式(URL、Method、参数、响应)
  • 🔧 辅助函数 — 自动生成 fillPath、buildQuery 工具函数

使用方法

  1. 点击 VS Code 左侧活动栏的 </> 图标(LeebApi)
  2. 在面板中:
    • URL 模式:输入 Swagger 地址,点击「获取」
    • JSON 模式:直接粘贴 Swagger JSON 内容
  3. 选择生成语言:TypeScript 或 JavaScript
  4. 选择输出目录,设置文件名前缀
  5. 点击「生成代码」

生成文件示例

swagger-api.types.ts

export interface User {
  id: number;
  name: string;
  email?: string;
}

swagger-api.api.ts

export const getUsersIdApi = {
  method: 'GET' as const,
  url: '/api/users/{id}' as const,
  pathParams: {} as { id: number },
  queryParams: {} as { expand?: string },
  response: {} as User,
};

安装

code --install-extension leeb-api-1.1.0.vsix

配置

配置项 说明 默认值
leebApi.defaultSwaggerUrl 默认 Swagger 地址 ""
leebApi.defaultOutputPrefix 默认文件名前缀 swagger-api
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft