@fxri/swagger2api 1.2.15 → 1.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,13 @@
1
- # @fxri/swagger2api
1
+ # Swagger 转 API
2
+
3
+ ## 1.2.16
4
+
5
+ > 2026-11-13 发布
6
+
7
+ ### ⚡ 优化改进
8
+
9
+ - 文档站导航与侧栏抽为 `docs/site-nav.json` 单一数据源,站点配置只做引用展开
10
+ - 导航与产物校验改由工具命令执行,删除三份本地校验脚本
2
11
 
3
12
  ## 1.2.15
4
13
 
package/NOTICE CHANGED
@@ -1,9 +1,9 @@
1
- @fxri/swagger2api
2
- Copyright © 2025-2026 唐启云. All rights reserved.
3
-
4
- 出品方:方弦研究所(唐启云个人项目品牌,非独立法人实体)
5
-
6
- 商标声明:
7
- "方弦®"为第42类注册商标(注册号89648411),核定服务项目:计算机出租、计算机软件设计、为他人研究和开发新产品、计算机软件维护、把有形的数据或文件转换成电子媒体、为他人创建和维护网站、网络服务器出租、提供互联网搜索引擎、托管计算机站(网站)、云计算。
8
- 本开源许可(MIT License)不授予商标使用权。
9
- 详见 TRADEMARK.md 了解完整商标信息。
1
+ @fxri/swagger2api
2
+ Copyright © 2025-2026 唐启云. All rights reserved.
3
+
4
+ 出品方:方弦研究所(唐启云个人项目品牌,非独立法人实体)
5
+
6
+ 商标声明:
7
+ "方弦®"为第42类注册商标(注册号89648411),核定服务项目:计算机出租、计算机软件设计、为他人研究和开发新产品、计算机软件维护、把有形的数据或文件转换成电子媒体、为他人创建和维护网站、网络服务器出租、提供互联网搜索引擎、托管计算机站(网站)、云计算。
8
+ 本开源许可(MIT License)不授予商标使用权。
9
+ 详见 TRADEMARK.md 了解完整商标信息。
package/README.md CHANGED
@@ -1,111 +1,111 @@
1
- <p align="center">
2
- <img src="./docs/public/logo.png" width="128" alt="Swagger 转 API">
3
- </p>
4
-
5
- # Swagger 转 API
6
-
7
- [![CI](https://github.com/fxri-net/swagger2api/actions/workflows/ci.yml/badge.svg)](https://github.com/fxri-net/swagger2api/actions/workflows/ci.yml)
8
- [![npm version](https://img.shields.io/npm/v/@fxri/swagger2api)](https://www.npmjs.com/package/@fxri/swagger2api)
9
- [![Node](https://img.shields.io/badge/node-%E2%89%A520.19-brightgreen)](./docs/getting-started.md#安装)
10
- [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
11
- [![文档站](https://img.shields.io/badge/docs-fxri--net.github.io%2Fswagger2api-blueviolet)](https://fxri-net.github.io/swagger2api/)
12
-
13
- > 国内网络建议优先 [Gitee 镜像](https://gitee.com/fxri/swagger2api)(与 GitHub 同源同步);问题反馈走 [GitHub Issues](https://github.com/fxri-net/swagger2api/issues) 或 [Gitee Issues](https://gitee.com/fxri/swagger2api/issues)。
14
-
15
- 基于 [swagger-typescript-api](https://github.com/acacode/swagger-typescript-api) 封装的 CLI 工具:Swagger 文档一键转 TS/JS 格式的 API 文件。
16
-
17
- 后端给到 Swagger 文档,接口代码还要照着手写;接口一多重名 `_n` 后缀满屏;多个项目的接口配置散落各处,更新要挨个跑命令。本工具把这些沉淀为**一行命令**:配置落盘可复用,生成静默无感,调用即取即用。
18
-
19
- - **多文档配置**:自动扫描项目下全部 `saconfig*.json`,多项目接口集中管理,搭配快速模式一行命令全量更新([怎么玩?](./docs/guide.md#多文档配置))
20
- - **唯一 operationId**:接口地址 + 请求方法拼接,从源头告别 `_n` 重名后缀([拼接规则](./docs/guide.md#唯一-operationid-拼接规则))
21
- - **不懂生成的代码也能用**:接口文件含请求方法与类型定义,导入即调;参数全部有默认值,交互引导填写([30 秒上手](./docs/getting-started.md))
22
-
23
- ## 🚀 30 秒上手
24
-
25
- ```bash
26
- # 1. 项目目录下临时执行(免安装;已安装则直接 swagger2api)
27
- pnpm dlx @fxri/swagger2api
28
-
29
- # 2. 按提示填写 Swagger 文档地址、输出目录、文件名
30
- # 自动生成接口代码与 saconfig.json 配置文件
31
- ```
32
-
33
- ```typescript
34
- import { Api } from "./src/api/index"
35
-
36
- /** 请求器 */
37
- export const request = new Api()
38
- request.getUsers().then((res) => console.log(res))
39
- ```
40
-
41
- 完整步骤见 [快速开始](./docs/getting-started.md)。
42
-
43
- ## ✨ 能力矩阵
44
-
45
- | 能力 | 适用场景 | 文档 |
46
- | --- | --- | --- |
47
- | 快速生成 | 从 Swagger JSON 生成 TS/JS 接口文件,含请求方法与类型定义 | [快速开始](./docs/getting-started.md) |
48
- | 多文档配置 | 自动扫描 `./**/saconfig*.json`,多项目接口配置集中管理 | [完整攻略](./docs/guide.md#多文档配置) |
49
- | 快速模式 | 配置齐全时跳过二次确认,搭配脚本一行命令静默更新 | [完整攻略](./docs/guide.md#快速模式) |
50
- | 唯一 operationId | 接口地址 + 请求方法拼接唯一 ID,可选 get 转 query 作区分 | [完整攻略](./docs/guide.md#唯一-operationid-拼接规则) |
51
- | 灵活裁剪 | 移除路径参数 / 前缀索引、替换标签、移除空组件定义 | [配置参考](./docs/config.md) |
52
- | 响应提取 | AxiosResponse 转移到 raw 字段,根部字段自行声明 | [完整攻略](./docs/guide.md#提取响应--extract-response-raw-err) |
53
- | STA 参数透传 | swagger-typescript-api 原生参数全量可用 | [CLI 参考](./docs/cli.md) |
54
-
55
- ## 📚 文档
56
-
57
- | 文档 | 适合谁 |
58
- | --- | --- |
59
- | [快速开始](./docs/getting-started.md) | 第一次接触,想 30 秒跑起来 |
60
- | [完整攻略](./docs/guide.md) | 日常使用:三种模式、响应提取、配置文件 |
61
- | [CLI 参考](./docs/cli.md) | 查命令、参数、默认值 |
62
- | [常见问题](./docs/faq.md) | 遇到问题先来这里找 |
63
- | [完整文档站](https://fxri-net.github.io/swagger2api/) | 在线阅读体验 |
64
-
65
- ## 📦 安装
66
-
67
- ```bash
68
- pnpm add -D @fxri/swagger2api # 项目依赖(团队推荐,版本随仓库锁定)
69
- pnpm i -g @fxri/swagger2api # 全局(个人多项目推荐)
70
- pnpm dlx @fxri/swagger2api # 不安装临时执行
71
- ```
72
-
73
- npm / yarn 用户、同名工具冲突说明见 [新手指南 · 安装](./docs/getting-started.md#安装)。
74
-
75
- ## 📁 多文档配置
76
-
77
- 默认配置文件为 `saconfig.json`;工具会扫描项目下所有 `saconfig*.json`(如 `saconfig.admin.json`、`config/saconfig.json`),多文件时提供选择列表。搭配快速模式与加载全部配置参数,`package.json` 一行脚本即可静默更新所有项目的接口代码:
78
-
79
- ```json
80
- {
81
- "scripts": {
82
- "api": "swagger2api --axios --responses -q -rpi 0 -err -ca"
83
- }
84
- }
85
- ```
86
-
87
- 此功能扩展使用的话,可以作为一个独立工具使用,同时管理多个项目的接口配置。详见 [完整攻略 · 多文档配置](./docs/guide.md#多文档配置)。
88
-
89
- ## ⚙️ 环境要求
90
-
91
- - Node.js >= 20.19.0
92
-
93
- ## 🛠️ 开发约定
94
-
95
- 构建、调试与验收命令见[完整攻略](https://fxri-net.github.io/swagger2api/guide.html)。
96
-
97
- ## 📄 版权信息
98
-
99
- 作者:唐启云 <tqy@fxri.net>
100
-
101
- 出品:方弦研究所
102
-
103
- 版权:Copyright © 2025-2026 唐启云. All rights reserved.
104
-
105
- 网站:[方弦研究信息网](https://fxri.net:444/)
106
-
107
- 协议:[MIT License](./LICENSE)
108
-
109
- 商标:"方弦®"为第42类注册商标(注册号89648411),本开源许可不授予商标使用权,详见 [TRADEMARK.md](./TRADEMARK.md)
110
-
111
- > 方弦研究所为唐启云个人项目品牌与出品方,非独立法人实体;本软件著作权归唐启云所有。
1
+ <p align="center">
2
+ <img src="./docs/public/logo.png" width="128" alt="Swagger 转 API">
3
+ </p>
4
+
5
+ # Swagger 转 API
6
+
7
+ [![CI](https://github.com/fxri-net/swagger2api/actions/workflows/ci.yml/badge.svg)](https://github.com/fxri-net/swagger2api/actions/workflows/ci.yml)
8
+ [![npm version](https://img.shields.io/npm/v/@fxri/swagger2api)](https://www.npmjs.com/package/@fxri/swagger2api)
9
+ [![Node](https://img.shields.io/badge/node-%E2%89%A520.19-brightgreen)](./docs/getting-started.md#安装)
10
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
11
+ [![文档站](https://img.shields.io/badge/docs-fxri--net.github.io%2Fswagger2api-blueviolet)](https://fxri-net.github.io/swagger2api/)
12
+
13
+ > 国内网络建议优先 [Gitee 镜像](https://gitee.com/fxri/swagger2api)(与 GitHub 同源同步);问题反馈走 [GitHub Issues](https://github.com/fxri-net/swagger2api/issues) 或 [Gitee Issues](https://gitee.com/fxri/swagger2api/issues)。
14
+
15
+ 基于 [swagger-typescript-api](https://github.com/acacode/swagger-typescript-api) 封装的 CLI 工具:Swagger 文档一键转 TS/JS 格式的 API 文件。
16
+
17
+ 后端给到 Swagger 文档,接口代码还要照着手写;接口一多重名 `_n` 后缀满屏;多个项目的接口配置散落各处,更新要挨个跑命令。本工具把这些沉淀为**一行命令**:配置落盘可复用,生成静默无感,调用即取即用。
18
+
19
+ - **多文档配置**:自动扫描项目下全部 `saconfig*.json`,多项目接口集中管理,搭配快速模式一行命令全量更新([怎么玩?](./docs/guide.md#多文档配置))
20
+ - **唯一 operationId**:接口地址 + 请求方法拼接,从源头告别 `_n` 重名后缀([拼接规则](./docs/guide.md#唯一-operationid-拼接规则))
21
+ - **不懂生成的代码也能用**:接口文件含请求方法与类型定义,导入即调;参数全部有默认值,交互引导填写([30 秒上手](./docs/getting-started.md))
22
+
23
+ ## 🚀 30 秒上手
24
+
25
+ ```bash
26
+ # 1. 项目目录下临时执行(免安装;已安装则直接 swagger2api)
27
+ pnpm dlx @fxri/swagger2api
28
+
29
+ # 2. 按提示填写 Swagger 文档地址、输出目录、文件名
30
+ # 自动生成接口代码与 saconfig.json 配置文件
31
+ ```
32
+
33
+ ```typescript
34
+ import { Api } from "./src/api/index"
35
+
36
+ /** 请求器 */
37
+ export const request = new Api()
38
+ request.getUsers().then((res) => console.log(res))
39
+ ```
40
+
41
+ 完整步骤见 [快速开始](./docs/getting-started.md)。
42
+
43
+ ## ✨ 能力矩阵
44
+
45
+ | 能力 | 适用场景 | 文档 |
46
+ | --- | --- | --- |
47
+ | 快速生成 | 从 Swagger JSON 生成 TS/JS 接口文件,含请求方法与类型定义 | [快速开始](./docs/getting-started.md) |
48
+ | 多文档配置 | 自动扫描 `./**/saconfig*.json`,多项目接口配置集中管理 | [完整攻略](./docs/guide.md#多文档配置) |
49
+ | 快速模式 | 配置齐全时跳过二次确认,搭配脚本一行命令静默更新 | [完整攻略](./docs/guide.md#快速模式) |
50
+ | 唯一 operationId | 接口地址 + 请求方法拼接唯一 ID,可选 get 转 query 作区分 | [完整攻略](./docs/guide.md#唯一-operationid-拼接规则) |
51
+ | 灵活裁剪 | 移除路径参数 / 前缀索引、替换标签、移除空组件定义 | [配置参考](./docs/config.md) |
52
+ | 响应提取 | AxiosResponse 转移到 raw 字段,根部字段自行声明 | [完整攻略](./docs/guide.md#提取响应--extract-response-raw-err) |
53
+ | STA 参数透传 | swagger-typescript-api 原生参数全量可用 | [CLI 参考](./docs/cli.md) |
54
+
55
+ ## 📚 文档
56
+
57
+ | 文档 | 适合谁 |
58
+ | --- | --- |
59
+ | [快速开始](./docs/getting-started.md) | 第一次接触,想 30 秒跑起来 |
60
+ | [完整攻略](./docs/guide.md) | 日常使用:三种模式、响应提取、配置文件 |
61
+ | [CLI 参考](./docs/cli.md) | 查命令、参数、默认值 |
62
+ | [常见问题](./docs/faq.md) | 遇到问题先来这里找 |
63
+ | [完整文档站](https://fxri-net.github.io/swagger2api/) | 在线阅读体验 |
64
+
65
+ ## 📦 安装
66
+
67
+ ```bash
68
+ pnpm add -D @fxri/swagger2api # 项目依赖(团队推荐,版本随仓库锁定)
69
+ pnpm i -g @fxri/swagger2api # 全局(个人多项目推荐)
70
+ pnpm dlx @fxri/swagger2api # 不安装临时执行
71
+ ```
72
+
73
+ npm / yarn 用户、同名工具冲突说明见 [新手指南 · 安装](./docs/getting-started.md#安装)。
74
+
75
+ ## 📁 多文档配置
76
+
77
+ 默认配置文件为 `saconfig.json`;工具会扫描项目下所有 `saconfig*.json`(如 `saconfig.admin.json`、`config/saconfig.json`),多文件时提供选择列表。搭配快速模式与加载全部配置参数,`package.json` 一行脚本即可静默更新所有项目的接口代码:
78
+
79
+ ```json
80
+ {
81
+ "scripts": {
82
+ "api": "swagger2api --axios --responses -q -rpi 0 -err -ca"
83
+ }
84
+ }
85
+ ```
86
+
87
+ 此功能扩展使用的话,可以作为一个独立工具使用,同时管理多个项目的接口配置。详见 [完整攻略 · 多文档配置](./docs/guide.md#多文档配置)。
88
+
89
+ ## ⚙️ 环境要求
90
+
91
+ - Node.js >= 20.19.0
92
+
93
+ ## 🛠️ 开发约定
94
+
95
+ 构建、调试与验收命令见[完整攻略](https://fxri-net.github.io/swagger2api/guide.html)。
96
+
97
+ ## 📄 版权信息
98
+
99
+ 作者:唐启云 <tqy@fxri.net>
100
+
101
+ 出品:方弦研究所
102
+
103
+ 版权:Copyright © 2025-2026 唐启云. All rights reserved.
104
+
105
+ 网站:[方弦研究信息网](https://fxri.net:444/)
106
+
107
+ 协议:[MIT License](./LICENSE)
108
+
109
+ 商标:"方弦®"为第42类注册商标(注册号89648411),本开源许可不授予商标使用权,详见 [TRADEMARK.md](./TRADEMARK.md)
110
+
111
+ > 方弦研究所为唐启云个人项目品牌与出品方,非独立法人实体;本软件著作权归唐启云所有。
@@ -1,32 +1,32 @@
1
- <%
2
- const { utils, config, routes, modelTypes } = it;
3
- const { _, pascalCase } = utils;
4
- const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
5
- %>
6
-
7
- <% if (dataContracts.length) { %>
8
- import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
9
- <% } %>
10
-
11
- <%
12
- /* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
13
- %>
14
-
15
- <% if (routes.outOfModule) { %>
16
- <% for (const { routes: outOfModuleRoutes = [] } of routes.outOfModule) { %>
17
- <% for (const route of outOfModuleRoutes) { %>
18
- <%~ includeFile('./route-type.ejs', { ...it, route }) %>
19
- <% } %>
20
- <% } %>
21
- <% } %>
22
-
23
- <% if (routes.combined) { %>
24
- <% for (const { routes: combinedRoutes = [], moduleName } of routes.combined) { %>
25
- export namespace <%~ pascalCase(moduleName) %> {
26
- <% for (const route of combinedRoutes) { %>
27
- <%~ includeFile('./route-type.ejs', { ...it, route }) %>
28
- <% } %>
29
- }
30
-
31
- <% } %>
32
- <% } %>
1
+ <%
2
+ const { utils, config, routes, modelTypes } = it;
3
+ const { _, pascalCase } = utils;
4
+ const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
5
+ %>
6
+
7
+ <% if (dataContracts.length) { %>
8
+ import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
9
+ <% } %>
10
+
11
+ <%
12
+ /* TODO: outOfModule, combined should be attributes of route, which will allow to avoid duplication of code */
13
+ %>
14
+
15
+ <% if (routes.outOfModule) { %>
16
+ <% for (const { routes: outOfModuleRoutes = [] } of routes.outOfModule) { %>
17
+ <% for (const route of outOfModuleRoutes) { %>
18
+ <%~ includeFile('./route-type.ejs', { ...it, route }) %>
19
+ <% } %>
20
+ <% } %>
21
+ <% } %>
22
+
23
+ <% if (routes.combined) { %>
24
+ <% for (const { routes: combinedRoutes = [], moduleName } of routes.combined) { %>
25
+ export namespace <%~ pascalCase(moduleName) %> {
26
+ <% for (const route of combinedRoutes) { %>
27
+ <%~ includeFile('./route-type.ejs', { ...it, route }) %>
28
+ <% } %>
29
+ }
30
+
31
+ <% } %>
32
+ <% } %>
@@ -1,15 +1,15 @@
1
- <%
2
- const { contract, utils } = it;
3
- const { formatDescription, require, _ } = utils;
4
-
5
- %>
6
- <% if (contract.$content.length) { %>
7
- export type <%~ contract.name %> = {
8
- <% for (const field of contract.$content) { %>
9
- <%~ includeFile('./object-field-jsdoc.ejs', { ...it, field }) %>
10
- <%~ field.field %>;
11
- <% } %>
12
- }<%~ utils.isNeedToAddNull(contract) ? ' | null' : ''%>
13
- <% } else { %>
14
- export type <%~ contract.name %> = Record<string, any>;
15
- <% } %>
1
+ <%
2
+ const { contract, utils } = it;
3
+ const { formatDescription, require, _ } = utils;
4
+
5
+ %>
6
+ <% if (contract.$content.length) { %>
7
+ export type <%~ contract.name %> = {
8
+ <% for (const field of contract.$content) { %>
9
+ <%~ includeFile('./object-field-jsdoc.ejs', { ...it, field }) %>
10
+ <%~ field.field %>;
11
+ <% } %>
12
+ }<%~ utils.isNeedToAddNull(contract) ? ' | null' : ''%>
13
+ <% } else { %>
14
+ export type <%~ contract.name %> = Record<string, any>;
15
+ <% } %>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fxri/swagger2api",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "description": "基于 swagger-typescript-api,将 Swagger 文档自动转为 TypeScript 格式的 API 文件。",
5
5
  "license": "MIT",
6
6
  "author": {