@aomex/openapi 0.0.37 → 1.0.3
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 +5 -83
- package/LICENSE +1 -1
- package/dist/index.d.ts +68 -42
- package/dist/index.js +315 -364
- package/dist/index.js.map +1 -1
- package/package.json +21 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,89 +1,11 @@
|
|
|
1
1
|
# @aomex/openapi
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.0.3
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- @aomex/web@0.0.29
|
|
9
|
-
- @aomex/core@0.0.28
|
|
10
|
-
- @aomex/router@0.0.31
|
|
11
|
-
- @aomex/console@0.0.33
|
|
7
|
+
- [`eb8b1eb`](https://github.com/aomex/aomex/commit/eb8b1ebdc7072d7ee9c7ba8e1f324e802753416d) Thanks [@geekact](https://github.com/geekact)! - feat(openapi): 文档生成工具
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- [`8becf8e`](https://github.com/aomex/aomex/commit/8becf8ee5ef86a5909783d0654e536db7be9bf5b) Thanks [@geekact](https://github.com/geekact)! - refactor(core): 工具移动到新的包@aomex/internal-tools
|
|
18
|
-
|
|
19
|
-
- [`0776719`](https://github.com/aomex/aomex/commit/077671963401f1dafb5b03722899452d45df13fc) Thanks [@geekact](https://github.com/geekact)! - refactor: 文件搜索转移到新的包@aomex/internal-file-import
|
|
20
|
-
|
|
21
|
-
- Updated dependencies [[`00bafbb`](https://github.com/aomex/aomex/commit/00bafbbac2d32205b63a6bf561fb0a69c38a54bb), [`8becf8e`](https://github.com/aomex/aomex/commit/8becf8ee5ef86a5909783d0654e536db7be9bf5b), [`0776719`](https://github.com/aomex/aomex/commit/077671963401f1dafb5b03722899452d45df13fc), [`f996bf7`](https://github.com/aomex/aomex/commit/f996bf7e529e7751a5e858c579feed33f5f02d65)]:
|
|
22
|
-
- @aomex/core@0.0.27
|
|
23
|
-
- @aomex/web@0.0.28
|
|
24
|
-
- @aomex/internal-tools@0.0.27
|
|
25
|
-
- @aomex/console@0.0.32
|
|
26
|
-
- @aomex/router@0.0.30
|
|
27
|
-
- @aomex/internal-file-import@0.0.27
|
|
28
|
-
|
|
29
|
-
## 0.0.35
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- Updated dependencies [[`33c3c61`](https://github.com/aomex/aomex/commit/33c3c614be9f66077f7487350b88d2db854f5fc8), [`fbcea3d`](https://github.com/aomex/aomex/commit/fbcea3d68ff033e6861130c645c8e5ad7336193f)]:
|
|
34
|
-
- @aomex/web@0.0.27
|
|
35
|
-
- @aomex/core@0.0.26
|
|
36
|
-
- @aomex/router@0.0.29
|
|
37
|
-
- @aomex/console@0.0.31
|
|
38
|
-
|
|
39
|
-
## 0.0.34
|
|
40
|
-
|
|
41
|
-
### Patch Changes
|
|
42
|
-
|
|
43
|
-
- Updated dependencies [[`5ef2022`](https://github.com/aomex/aomex/commit/5ef202248b4320ff9076fbecb54379055cffb7db), [`8d9e9d8`](https://github.com/aomex/aomex/commit/8d9e9d8ece0bbcc7e1ac685702eacbfdfa145aa9), [`28f5a17`](https://github.com/aomex/aomex/commit/28f5a17b638ec646ccdade2ea567f195f9174340), [`0e6ed2c`](https://github.com/aomex/aomex/commit/0e6ed2c611100dcfaafb6fb41357624ad9f5c67a)]:
|
|
44
|
-
- @aomex/web@0.0.26
|
|
45
|
-
- @aomex/router@0.0.28
|
|
46
|
-
- @aomex/core@0.0.25
|
|
47
|
-
- @aomex/console@0.0.30
|
|
48
|
-
|
|
49
|
-
## 0.0.33
|
|
50
|
-
|
|
51
|
-
### Patch Changes
|
|
52
|
-
|
|
53
|
-
- [`2ac62fd`](https://github.com/aomex/aomex/commit/2ac62fd28166a1d9dd60b3c6d5a6508a6f9ee82b) Thanks [@geekact](https://github.com/geekact)! - feat!(openapi): remove function createSchema
|
|
54
|
-
|
|
55
|
-
- Updated dependencies [[`2ac62fd`](https://github.com/aomex/aomex/commit/2ac62fd28166a1d9dd60b3c6d5a6508a6f9ee82b), [`4258410`](https://github.com/aomex/aomex/commit/42584107ad9f7e34492ae1053fef83aa2d9d747a), [`4177cba`](https://github.com/aomex/aomex/commit/4177cba7877e38120842bd8d287eaed54e4926ca)]:
|
|
56
|
-
- @aomex/core@0.0.24
|
|
57
|
-
- @aomex/console@0.0.29
|
|
58
|
-
- @aomex/router@0.0.27
|
|
59
|
-
- @aomex/web@0.0.25
|
|
60
|
-
|
|
61
|
-
## 0.0.32
|
|
62
|
-
|
|
63
|
-
### Patch Changes
|
|
64
|
-
|
|
65
|
-
- [`484849e`](https://github.com/aomex/aomex/commit/484849e1930c9b78bd6d735eb52bdbfea175e79b) Thanks [@geekact](https://github.com/geekact)! - refactor(openapi): 使用中文
|
|
66
|
-
|
|
67
|
-
- Updated dependencies [[`6621e4f`](https://github.com/aomex/aomex/commit/6621e4ff0f3509beeb332a0571a7db9c7d6ca99a), [`7b09277`](https://github.com/aomex/aomex/commit/7b09277136910966f500c8132303c7ddee84340c), [`46c5b72`](https://github.com/aomex/aomex/commit/46c5b72785011fa181767f4c8ea0d0f5008b21ae), [`9c78999`](https://github.com/aomex/aomex/commit/9c78999ebcb2962f30344acfbf6de0733d6fdd41), [`f4b012d`](https://github.com/aomex/aomex/commit/f4b012d98cddb2918479ea05df6c266dd914e53a), [`95fd705`](https://github.com/aomex/aomex/commit/95fd705d2ac24f4a3c14446ccb9de6eb6817d0cd)]:
|
|
68
|
-
- @aomex/web@0.0.24
|
|
69
|
-
- @aomex/core@0.0.23
|
|
70
|
-
- @aomex/console@0.0.28
|
|
71
|
-
- @aomex/router@0.0.26
|
|
72
|
-
|
|
73
|
-
## 0.0.31
|
|
74
|
-
|
|
75
|
-
### Patch Changes
|
|
76
|
-
|
|
77
|
-
- [`e7bf93c`](https://github.com/aomex/aomex/commit/e7bf93cee6896c61d0bf3eb0921151dc6c1bc107) Thanks [@geekact](https://github.com/geekact)! - chore(openapi): 升级依赖 @stoplight/spectral-core 1.17.0 -> 1.18.2
|
|
78
|
-
chore(openapi): 升级依赖 @stoplight/spectral-rulesets 1.15.0 -> 1.16.0
|
|
79
|
-
chore(openapi): 升级依赖 ora 6.3.0 -> 6.3.1
|
|
80
|
-
chore(openapi): 升级依赖 read-pkg-up 9.1.0 -> 10.0.0
|
|
81
|
-
chore(openapi): 升级依赖 yaml 2.2.1 -> 2.3.1
|
|
82
|
-
|
|
83
|
-
- [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5) Thanks [@geekact](https://github.com/geekact)! - refactor(core): 对象使用统一逻辑转换成验证器
|
|
84
|
-
|
|
85
|
-
- Updated dependencies [[`6f7d706`](https://github.com/aomex/aomex/commit/6f7d7066c23711abdd149eb1c9a293ab8c4284a4), [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159), [`e7bf93c`](https://github.com/aomex/aomex/commit/e7bf93cee6896c61d0bf3eb0921151dc6c1bc107), [`e21007a`](https://github.com/aomex/aomex/commit/e21007a82cb8eac73e1f696340bbe986d57dc159), [`818e840`](https://github.com/aomex/aomex/commit/818e840d36c7456a863fc071968b246c123c17f5), [`fb6c72d`](https://github.com/aomex/aomex/commit/fb6c72dbb266be4db92a542afe93dfa5d8c7cd41)]:
|
|
86
|
-
- @aomex/core@0.0.22
|
|
87
|
-
- @aomex/web@0.0.23
|
|
88
|
-
- @aomex/console@0.0.27
|
|
89
|
-
- @aomex/router@0.0.25
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @aomex/internal-file-import@1.0.3
|
|
11
|
+
- @aomex/internal-tools@1.0.3
|
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,64 +1,90 @@
|
|
|
1
|
-
import
|
|
2
|
-
import EventEmitter from 'node:events';
|
|
1
|
+
import { ConsoleMiddleware } from '@aomex/console';
|
|
3
2
|
import { Mode } from 'node:fs';
|
|
4
|
-
import { OpenAPI } from '@aomex/core';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
interface OpenapiValidateResultItem {
|
|
8
|
-
path: string[];
|
|
9
|
-
message: string;
|
|
10
|
-
}
|
|
11
|
-
interface OpenapiValidateResult {
|
|
12
|
-
errors: OpenapiValidateResultItem[];
|
|
13
|
-
warnings: OpenapiValidateResultItem[];
|
|
14
|
-
}
|
|
3
|
+
import { OpenAPI, I18nFormat } from '@aomex/core';
|
|
4
|
+
import { GlobPathOptions } from '@aomex/internal-file-import';
|
|
15
5
|
|
|
16
6
|
interface OpenapiOptions {
|
|
17
7
|
/**
|
|
18
|
-
*
|
|
8
|
+
* http接口路由文件
|
|
19
9
|
*/
|
|
20
|
-
routers:
|
|
10
|
+
routers: GlobPathOptions;
|
|
21
11
|
/**
|
|
22
|
-
* Openapi
|
|
23
|
-
* @see OpenApiDocs
|
|
12
|
+
* Openapi基础信息
|
|
24
13
|
*/
|
|
25
14
|
docs?: Omit<OpenAPI.Document, 'paths' | 'openapi' | 'info'> & {
|
|
26
15
|
openapi?: `3.0.${0 | 1 | 2 | 3}`;
|
|
27
16
|
info?: Partial<OpenAPI.Document['info']>;
|
|
28
17
|
};
|
|
29
18
|
/**
|
|
30
|
-
*
|
|
19
|
+
* 保存到指定文件。默认值:`openapi.json`
|
|
20
|
+
* - `*.json` 保存为JSON格式
|
|
21
|
+
* - `*.yml` 保存为YAML格式
|
|
22
|
+
* - `*.yaml` 保存为YAML格式
|
|
31
23
|
*/
|
|
32
|
-
|
|
24
|
+
saveToFile?: false | string;
|
|
33
25
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @see OpenapiOptions.output
|
|
26
|
+
* 设置保存文件的系统权限。
|
|
36
27
|
*/
|
|
37
28
|
fileMode?: Mode;
|
|
38
29
|
/**
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
prettyJson?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Fix the document by hand after the full document is generated
|
|
30
|
+
* 手动修复文档内容
|
|
44
31
|
*/
|
|
45
|
-
fix?: (data: OpenAPI.Document) => void
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
fix?: (data: OpenAPI.Document) => void | Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
declare const generateDocument: (config: OpenapiOptions) => Promise<OpenAPI.Document>;
|
|
35
|
+
|
|
36
|
+
declare const openapi: (options: OpenapiOptions) => ConsoleMiddleware;
|
|
37
|
+
|
|
38
|
+
declare module '@aomex/core' {
|
|
39
|
+
namespace I18n {
|
|
40
|
+
interface Definition {
|
|
41
|
+
openapi: {
|
|
42
|
+
initialize: I18nFormat;
|
|
43
|
+
search_routers_files: I18nFormat;
|
|
44
|
+
parse_routers: I18nFormat;
|
|
45
|
+
add_tag: I18nFormat;
|
|
46
|
+
hand_fix_documentation: I18nFormat;
|
|
47
|
+
optimize_parameter: I18nFormat;
|
|
48
|
+
save_to_file: I18nFormat;
|
|
49
|
+
validate: I18nFormat;
|
|
50
|
+
help_summary: I18nFormat;
|
|
51
|
+
has_error: I18nFormat<{
|
|
52
|
+
count: number;
|
|
53
|
+
}>;
|
|
54
|
+
has_warning: I18nFormat<{
|
|
55
|
+
count: number;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
|
|
62
|
+
declare const initializeDocument: (basic?: OpenapiOptions['docs']) => Promise<OpenAPI.Document<{}>>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 同一个路径下,所有方法都有相同的parameter时,可以往上提取,这样能减小生成产物
|
|
66
|
+
*/
|
|
67
|
+
declare const methodParameterToPathParameter: (document: OpenAPI.Document) => void;
|
|
68
|
+
|
|
69
|
+
declare const methodToVerb: (method: string, uri: string) => string;
|
|
70
|
+
|
|
71
|
+
declare const methods: readonly ["get", "post", "put", "patch", "delete", "options", "head", "trace"];
|
|
72
|
+
|
|
73
|
+
declare const parseFiles: (document: OpenAPI.Document, files: string[]) => Promise<string[]>;
|
|
74
|
+
|
|
75
|
+
declare const saveToFile: (document: OpenAPI.Document, filename?: string, fileMode?: Mode) => Promise<{
|
|
76
|
+
dest: string;
|
|
77
|
+
size: string;
|
|
54
78
|
}>;
|
|
55
79
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
80
|
+
interface OpenapiValidateResultItem {
|
|
81
|
+
path: string[];
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
interface OpenapiValidateResult {
|
|
85
|
+
errors: OpenapiValidateResultItem[];
|
|
86
|
+
warnings: OpenapiValidateResultItem[];
|
|
87
|
+
}
|
|
88
|
+
declare const validateOpenapi: (document: OpenAPI.Document) => Promise<OpenapiValidateResult>;
|
|
63
89
|
|
|
64
|
-
export { OpenapiOptions, generateDocument, openapi };
|
|
90
|
+
export { type OpenapiOptions, type OpenapiValidateResult, type OpenapiValidateResultItem, generateDocument, initializeDocument, methodParameterToPathParameter, methodToVerb, methods, openapi, parseFiles, saveToFile, validateOpenapi };
|
package/dist/index.js
CHANGED
|
@@ -1,191 +1,13 @@
|
|
|
1
1
|
// src/openapi.ts
|
|
2
|
-
import
|
|
3
|
-
import { chain, middleware as middleware2 } from "@aomex/core";
|
|
4
|
-
import { chalk as chalk3 } from "@aomex/internal-tools";
|
|
5
|
-
import ora from "ora";
|
|
2
|
+
import { i18n as i18n2, middleware } from "@aomex/core";
|
|
6
3
|
|
|
7
|
-
// src/
|
|
8
|
-
import {
|
|
9
|
-
import { middleware } from "@aomex/core";
|
|
4
|
+
// src/lib/generate-document.ts
|
|
5
|
+
import { i18n } from "@aomex/core";
|
|
10
6
|
import { chalk } from "@aomex/internal-tools";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
all(yargs) {
|
|
14
|
-
yargs.command(
|
|
15
|
-
chalk.yellow(commandName),
|
|
16
|
-
summary || "Generate openapi v3 documentation"
|
|
17
|
-
);
|
|
18
|
-
},
|
|
19
|
-
detailCommand: () => showInHelp && ctx.request.command === commandName,
|
|
20
|
-
detail(yargs) {
|
|
21
|
-
yargs.usage(
|
|
22
|
-
`${scriptName} ${commandName} [options]${description ? "\n\n" + chalk.bold(description) : ""}`
|
|
23
|
-
);
|
|
24
|
-
},
|
|
25
|
-
next
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// src/generate-document.ts
|
|
30
|
-
import EventEmitter from "node:events";
|
|
31
|
-
import { readPackageUp } from "read-pkg-up";
|
|
32
|
-
import snakeCase from "lodash.snakecase";
|
|
33
|
-
import { Chain } from "@aomex/core";
|
|
34
|
-
import { bytes, chalk as chalk2, sleep } from "@aomex/internal-tools";
|
|
35
|
-
import {
|
|
36
|
-
fileToModules,
|
|
37
|
-
pathToFiles
|
|
38
|
-
} from "@aomex/internal-file-import";
|
|
39
|
-
import { METHOD as METHOD2, WebMiddleware } from "@aomex/web";
|
|
40
|
-
import { Router } from "@aomex/router";
|
|
41
|
-
import path from "node:path";
|
|
42
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
43
|
-
import yaml from "yaml";
|
|
44
|
-
|
|
45
|
-
// src/lib/parameter.ts
|
|
46
|
-
import { METHOD } from "@aomex/web";
|
|
47
|
-
var parameterToComponent = (document) => {
|
|
48
|
-
const parametersStringify = [];
|
|
49
|
-
const parametersRef = /* @__PURE__ */ new Map();
|
|
50
|
-
let count = 0;
|
|
51
|
-
document.components ||= {};
|
|
52
|
-
document.components.parameters ||= {};
|
|
53
|
-
const parser = (parameter, index, arr) => {
|
|
54
|
-
if ("$ref" in parameter)
|
|
55
|
-
return;
|
|
56
|
-
const str = JSON.stringify(parameter);
|
|
57
|
-
const replace = (ref) => {
|
|
58
|
-
arr[index] = {
|
|
59
|
-
$ref: "#/components/parameters/" + ref
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
if (parametersStringify.includes(str)) {
|
|
63
|
-
let ref = parametersRef.get(str);
|
|
64
|
-
if (typeof ref === "function") {
|
|
65
|
-
const firstReplace = ref;
|
|
66
|
-
const name = parameter.name;
|
|
67
|
-
ref = document.components.parameters[name] ? name + "_" + ++count : name;
|
|
68
|
-
document.components.parameters[ref] = parameter;
|
|
69
|
-
parametersRef.set(str, ref);
|
|
70
|
-
firstReplace(ref);
|
|
71
|
-
}
|
|
72
|
-
replace(ref);
|
|
73
|
-
} else {
|
|
74
|
-
parametersStringify.push(str);
|
|
75
|
-
parametersRef.set(str, replace);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
for (const path2 of Object.values(document.paths)) {
|
|
79
|
-
path2.parameters?.forEach(parser);
|
|
80
|
-
for (const method of methods) {
|
|
81
|
-
const methodItem = path2[method];
|
|
82
|
-
if (!methodItem || !methodItem.parameters)
|
|
83
|
-
continue;
|
|
84
|
-
methodItem.parameters.forEach(parser);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (Object.keys(document.components.parameters).length === 0) {
|
|
88
|
-
delete document.components.parameters;
|
|
89
|
-
}
|
|
90
|
-
if (Object.keys(document.components).length === 0) {
|
|
91
|
-
delete document.components;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
var methodParameterToPathParameter = (document) => {
|
|
95
|
-
pathLoop:
|
|
96
|
-
for (const path2 of Object.values(document.paths)) {
|
|
97
|
-
const parametersCallback = {};
|
|
98
|
-
let index = 0;
|
|
99
|
-
for (const method of methods) {
|
|
100
|
-
const methodItem = path2[method];
|
|
101
|
-
if (!methodItem)
|
|
102
|
-
continue;
|
|
103
|
-
if (!methodItem.parameters?.length)
|
|
104
|
-
continue pathLoop;
|
|
105
|
-
++index;
|
|
106
|
-
methodItem.parameters.forEach((parameter, index2, arr) => {
|
|
107
|
-
const str = JSON.stringify(parameter);
|
|
108
|
-
parameter = arr[index2] = JSON.parse(str);
|
|
109
|
-
parametersCallback[str] ||= [];
|
|
110
|
-
parametersCallback[str].push(() => {
|
|
111
|
-
arr.splice(
|
|
112
|
-
arr.findIndex((item) => item === parameter),
|
|
113
|
-
1
|
|
114
|
-
);
|
|
115
|
-
if (!arr.length) {
|
|
116
|
-
delete methodItem.parameters;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
if (index < 2)
|
|
122
|
-
continue pathLoop;
|
|
123
|
-
Object.entries(parametersCallback).forEach(([key, callbacks]) => {
|
|
124
|
-
if (callbacks.length !== index)
|
|
125
|
-
return;
|
|
126
|
-
path2.parameters ||= [];
|
|
127
|
-
path2.parameters.push(JSON.parse(key));
|
|
128
|
-
callbacks.forEach((callback) => callback());
|
|
129
|
-
});
|
|
130
|
-
if (path2.parameters && !path2.parameters.length) {
|
|
131
|
-
delete path2.parameters;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
var methods = Object.values(METHOD).map(
|
|
136
|
-
(method) => method.toLowerCase()
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
// src/lib/method-to-verb.ts
|
|
140
|
-
var methodToVerb = (method, uri) => {
|
|
141
|
-
method = method.toLowerCase();
|
|
142
|
-
if (method === "get" && !uri.includes(":"))
|
|
143
|
-
return "list";
|
|
144
|
-
if (method === "post")
|
|
145
|
-
return "create";
|
|
146
|
-
if (method === "put")
|
|
147
|
-
return "replace";
|
|
148
|
-
if (method === "patch")
|
|
149
|
-
return "update";
|
|
150
|
-
return method;
|
|
151
|
-
};
|
|
7
|
+
import { pathToFiles } from "@aomex/internal-file-import";
|
|
8
|
+
import path3 from "node:path";
|
|
152
9
|
|
|
153
|
-
// src/lib/
|
|
154
|
-
var removeDuplicateSchema = (document) => {
|
|
155
|
-
document.components ||= {};
|
|
156
|
-
document.components.schemas ||= {};
|
|
157
|
-
const schemas = document.components.schemas;
|
|
158
|
-
(function loopSearch(docs) {
|
|
159
|
-
if (typeof docs !== "object")
|
|
160
|
-
return;
|
|
161
|
-
Object.entries(docs).forEach(([key, value]) => {
|
|
162
|
-
if (value === schemas)
|
|
163
|
-
return;
|
|
164
|
-
if (!isValidSchemaObject(value)) {
|
|
165
|
-
return loopSearch(value);
|
|
166
|
-
}
|
|
167
|
-
const ref = value["x-schema-ref"];
|
|
168
|
-
docs[key] = {
|
|
169
|
-
$ref: "#/components/schemas/" + ref
|
|
170
|
-
};
|
|
171
|
-
if (!schemas[ref]) {
|
|
172
|
-
Reflect.deleteProperty(value, "x-schema-ref");
|
|
173
|
-
schemas[ref] = value;
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
})(document);
|
|
177
|
-
if (Object.keys(document.components.schemas).length === 0) {
|
|
178
|
-
delete document.components.schemas;
|
|
179
|
-
}
|
|
180
|
-
if (Object.keys(document.components).length === 0) {
|
|
181
|
-
delete document.components;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
var isValidSchemaObject = (value) => {
|
|
185
|
-
return typeof value === "object" && !!value["type"] && !!value["x-schema-ref"];
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// src/lib/validate.ts
|
|
10
|
+
// src/lib/validate-openapi.ts
|
|
189
11
|
import stoplight from "@stoplight/spectral-core";
|
|
190
12
|
import { oas } from "@stoplight/spectral-rulesets";
|
|
191
13
|
var spectral = new stoplight.Spectral();
|
|
@@ -197,14 +19,12 @@ spectral.setRuleset({
|
|
|
197
19
|
"info-description": "off"
|
|
198
20
|
}
|
|
199
21
|
});
|
|
200
|
-
var
|
|
22
|
+
var validateOpenapi = async (document) => {
|
|
201
23
|
const result = {
|
|
202
24
|
warnings: [],
|
|
203
25
|
errors: []
|
|
204
26
|
};
|
|
205
|
-
const originResult = await spectral.run(
|
|
206
|
-
document
|
|
207
|
-
);
|
|
27
|
+
const originResult = await spectral.run(document);
|
|
208
28
|
originResult.forEach((item) => {
|
|
209
29
|
result[item.severity === 0 /* Error */ ? "errors" : "warnings"].push({
|
|
210
30
|
path: item.path.map(String),
|
|
@@ -214,227 +34,358 @@ var validate = async (document) => {
|
|
|
214
34
|
return result;
|
|
215
35
|
};
|
|
216
36
|
|
|
217
|
-
// src/
|
|
218
|
-
var
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
37
|
+
// src/lib/methods.ts
|
|
38
|
+
var methods = [
|
|
39
|
+
"get",
|
|
40
|
+
"post",
|
|
41
|
+
"put",
|
|
42
|
+
"patch",
|
|
43
|
+
"delete",
|
|
44
|
+
"options",
|
|
45
|
+
"head",
|
|
46
|
+
"trace"
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
// src/lib/method-parameter-to-path-parameter.ts
|
|
50
|
+
var methodParameterToPathParameter = (document) => {
|
|
51
|
+
pathLoop: for (const path4 of Object.values(document.paths)) {
|
|
52
|
+
const parametersHandler = {};
|
|
53
|
+
let methodCounter = 0;
|
|
54
|
+
for (const method of methods) {
|
|
55
|
+
const methodItem = path4[method];
|
|
56
|
+
if (!methodItem) continue;
|
|
57
|
+
if (!methodItem.parameters?.length) continue pathLoop;
|
|
58
|
+
++methodCounter;
|
|
59
|
+
methodItem.parameters.forEach((parameter, index, arr) => {
|
|
60
|
+
const uniqueKey = JSON.stringify(parameter);
|
|
61
|
+
parameter = arr[index] = JSON.parse(uniqueKey);
|
|
62
|
+
const handler = () => {
|
|
63
|
+
arr.splice(
|
|
64
|
+
arr.findIndex((item) => item === parameter),
|
|
65
|
+
1
|
|
66
|
+
);
|
|
67
|
+
if (!arr.length) {
|
|
68
|
+
delete methodItem.parameters;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
parametersHandler[uniqueKey] ||= [];
|
|
72
|
+
parametersHandler[uniqueKey].push(handler);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (methodCounter < 2) continue pathLoop;
|
|
76
|
+
Object.entries(parametersHandler).forEach(([uniqueKey, handlers]) => {
|
|
77
|
+
if (handlers.length !== methodCounter) return;
|
|
78
|
+
path4.parameters ||= [];
|
|
79
|
+
path4.parameters.push(JSON.parse(uniqueKey));
|
|
80
|
+
handlers.forEach((fn) => fn());
|
|
81
|
+
});
|
|
82
|
+
if (path4.parameters && !path4.parameters.length) {
|
|
83
|
+
delete path4.parameters;
|
|
84
|
+
}
|
|
233
85
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/lib/save-to-file.ts
|
|
89
|
+
import path from "node:path";
|
|
90
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
91
|
+
import YAML from "yaml";
|
|
92
|
+
import { bytes } from "@aomex/internal-tools";
|
|
93
|
+
var saveToFile = async (document, filename, fileMode) => {
|
|
94
|
+
const dest = path.resolve(filename || "openapi.json");
|
|
95
|
+
const content = [".yml", ".yaml"].includes(path.extname(dest)) ? YAML.stringify(document) : JSON.stringify(document);
|
|
96
|
+
const size = bytes(Buffer.byteLength(content), { unitSeparator: "" });
|
|
97
|
+
await mkdir(path.dirname(dest), { recursive: true });
|
|
98
|
+
await writeFile(dest, content, { mode: fileMode });
|
|
99
|
+
return { dest, size };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/lib/initialize-document.ts
|
|
103
|
+
import { readPackageUp } from "read-package-up";
|
|
104
|
+
var initializeDocument = async (basic) => {
|
|
105
|
+
const document = JSON.parse(JSON.stringify(basic || {}));
|
|
106
|
+
document.openapi ||= "3.0.3";
|
|
107
|
+
document.tags ||= [];
|
|
108
|
+
document.info ||= { title: "", version: "" };
|
|
109
|
+
document.paths = {};
|
|
110
|
+
document.info.title ||= (await readPackageUp())?.packageJson.name || "OpenAPI";
|
|
111
|
+
document.info.version ||= (await readPackageUp())?.packageJson.version || "0.0.0";
|
|
112
|
+
return document;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/lib/generate-document.ts
|
|
116
|
+
import { Listr } from "listr2";
|
|
117
|
+
|
|
118
|
+
// src/lib/parse-files.ts
|
|
119
|
+
import { flattenMiddlewareToken } from "@aomex/core";
|
|
120
|
+
import { getFileValues } from "@aomex/internal-file-import";
|
|
121
|
+
import { Router } from "@aomex/router";
|
|
122
|
+
import { WebMiddleware } from "@aomex/web";
|
|
123
|
+
import path2 from "node:path";
|
|
124
|
+
|
|
125
|
+
// src/lib/method-to-verb.ts
|
|
126
|
+
var methodToVerb = (method, uri) => {
|
|
127
|
+
method = method.toLowerCase();
|
|
128
|
+
if (method === "get") return uri.includes(":") ? "retrieve" : "list";
|
|
129
|
+
if (method === "post") return "create";
|
|
130
|
+
if (method === "put") return "replace";
|
|
131
|
+
if (method === "patch") return "update";
|
|
132
|
+
return method;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/lib/parse-files.ts
|
|
136
|
+
import snakeCase from "lodash.snakecase";
|
|
137
|
+
var parseFiles = async (document, files) => {
|
|
237
138
|
const usedTags = [];
|
|
139
|
+
const data = [];
|
|
238
140
|
for (const file of files) {
|
|
239
|
-
|
|
240
|
-
"replace",
|
|
241
|
-
msg + " " + chalk2.gray(
|
|
242
|
-
path.relative(process.cwd(), file).split(path.sep).join(path.posix.sep)
|
|
243
|
-
)
|
|
244
|
-
);
|
|
245
|
-
await sleep(50);
|
|
246
|
-
const routers = await fileToModules(
|
|
141
|
+
const routers = await getFileValues(
|
|
247
142
|
[file],
|
|
248
143
|
(item) => !!item && item instanceof Router
|
|
249
144
|
);
|
|
250
145
|
for (const router of routers) {
|
|
251
|
-
const groupMiddlewareList =
|
|
146
|
+
const groupMiddlewareList = flattenMiddlewareToken(router["middlewareChain"]);
|
|
252
147
|
const builders = router["builders"];
|
|
253
148
|
for (const builder of builders) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
149
|
+
const builderMiddlewareList = groupMiddlewareList.concat(builder["middlewareList"]).filter((middleware2) => middleware2 instanceof WebMiddleware);
|
|
150
|
+
for (const uri of builder["uris"]) {
|
|
151
|
+
const pathName = normalizePath(uri);
|
|
152
|
+
const pathItem = document.paths[pathName] ||= {};
|
|
153
|
+
let methods2 = builder["methods"];
|
|
154
|
+
if (methods2.includes("GET") && methods2.includes("HEAD")) {
|
|
258
155
|
methods2 = methods2.filter((method) => method !== "HEAD");
|
|
259
156
|
}
|
|
260
157
|
for (const method of methods2) {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
...builder.docs
|
|
158
|
+
const methodName = method.toLowerCase();
|
|
159
|
+
const methodItem = pathItem[methodName] = {
|
|
160
|
+
...builder.docs,
|
|
161
|
+
responses: {}
|
|
264
162
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
middleware3.toDocument({
|
|
270
|
-
document,
|
|
163
|
+
data.push(
|
|
164
|
+
...builderMiddlewareList.map((item) => {
|
|
165
|
+
return {
|
|
166
|
+
injector: item["openapi"](),
|
|
271
167
|
pathItem,
|
|
272
|
-
|
|
273
|
-
methodItem
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
methodToVerb(method, uri) + " " + uri.replaceAll(":", "_by_")
|
|
168
|
+
pathName,
|
|
169
|
+
methodItem,
|
|
170
|
+
methodName,
|
|
171
|
+
file,
|
|
172
|
+
uri
|
|
173
|
+
};
|
|
174
|
+
})
|
|
280
175
|
);
|
|
281
|
-
if (method === METHOD2.POST) {
|
|
282
|
-
methodItem["x-codegen-request-body-name"] = "body";
|
|
283
|
-
}
|
|
284
|
-
if (Object.keys(methodItem.responses).length === 0) {
|
|
285
|
-
methodItem.responses = {
|
|
286
|
-
default: {
|
|
287
|
-
description: ""
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
usedTags.push(...methodItem.tags);
|
|
292
176
|
}
|
|
293
177
|
}
|
|
294
178
|
}
|
|
295
179
|
}
|
|
296
180
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const tags = document.tags;
|
|
300
|
-
const definedTags = tags.map((item) => item.name);
|
|
301
|
-
for (const tag of [...new Set(usedTags)].sort()) {
|
|
302
|
-
if (!definedTags.includes(tag)) {
|
|
303
|
-
emitter.emit("msg", msg = `\u589E\u52A0\u6807\u7B7E\uFF1A${tag}`);
|
|
304
|
-
tags.push({ name: tag });
|
|
305
|
-
}
|
|
306
|
-
}
|
|
181
|
+
for (const { injector } of data) {
|
|
182
|
+
injector.onDocument?.(document);
|
|
307
183
|
}
|
|
308
|
-
{
|
|
309
|
-
|
|
310
|
-
if (config.fix) {
|
|
311
|
-
config.fix(document);
|
|
312
|
-
} else {
|
|
313
|
-
emitter.emit("replace", skip(msg));
|
|
314
|
-
}
|
|
184
|
+
for (const { injector, pathItem, pathName } of data) {
|
|
185
|
+
injector.onPath?.(pathItem, { document, pathName });
|
|
315
186
|
}
|
|
316
|
-
{
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
187
|
+
for (const { injector, pathItem, pathName, methodItem, methodName } of data) {
|
|
188
|
+
injector.onMethod?.(methodItem, {
|
|
189
|
+
document,
|
|
190
|
+
pathItem,
|
|
191
|
+
pathName,
|
|
192
|
+
methodName
|
|
193
|
+
});
|
|
320
194
|
}
|
|
321
|
-
{
|
|
322
|
-
|
|
323
|
-
|
|
195
|
+
for (const { injector, pathItem, pathName, methodItem, methodName } of data) {
|
|
196
|
+
injector.postMethod?.(methodItem, {
|
|
197
|
+
document,
|
|
198
|
+
pathItem,
|
|
199
|
+
pathName,
|
|
200
|
+
methodName
|
|
201
|
+
});
|
|
324
202
|
}
|
|
325
|
-
{
|
|
326
|
-
|
|
327
|
-
let distFile = config.output === false ? false : config.output || "openapi.json";
|
|
328
|
-
if (distFile) {
|
|
329
|
-
distFile = path.resolve(distFile);
|
|
330
|
-
await mkdir(path.dirname(distFile), {
|
|
331
|
-
recursive: true
|
|
332
|
-
});
|
|
333
|
-
const content = [".yml", ".yaml"].includes(path.extname(distFile)) ? yaml.stringify(document) : JSON.stringify(document, null, config.prettyJson ? 2 : void 0);
|
|
334
|
-
await writeFile(distFile, content, {
|
|
335
|
-
mode: config.fileMode
|
|
336
|
-
});
|
|
337
|
-
const size = bytes(Buffer.byteLength(content), { unitSeparator: "" });
|
|
338
|
-
emitter.emit(
|
|
339
|
-
"replace",
|
|
340
|
-
msg + ": " + path.relative(process.cwd(), distFile) + chalk2.gray(` [${size}]`),
|
|
341
|
-
true
|
|
342
|
-
);
|
|
343
|
-
} else {
|
|
344
|
-
emitter.emit("replace", skip(msg));
|
|
345
|
-
}
|
|
203
|
+
for (const { injector, pathItem, pathName } of data) {
|
|
204
|
+
injector.postPath?.(pathItem, { document, pathName });
|
|
346
205
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
emitter.emit("msg", msg = "\u9A8C\u8BC1");
|
|
350
|
-
result = await validate(document);
|
|
206
|
+
for (const { injector } of data) {
|
|
207
|
+
injector.postDocument?.(document);
|
|
351
208
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
209
|
+
for (const { methodItem, methodName, file, uri } of data) {
|
|
210
|
+
methodItem.tags ||= [getTagByFilename(file)];
|
|
211
|
+
methodItem.operationId ||= snakeCase(
|
|
212
|
+
methodToVerb(methodName, uri) + " " + uri.replaceAll(":", "_by_")
|
|
213
|
+
);
|
|
214
|
+
if (methodName === "post") {
|
|
215
|
+
methodItem["x-codegen-request-body-name"] = "body";
|
|
357
216
|
}
|
|
358
|
-
|
|
217
|
+
if (!Object.keys(methodItem.responses).length) {
|
|
218
|
+
methodItem.responses = { default: { description: "" } };
|
|
219
|
+
}
|
|
220
|
+
usedTags.push(...methodItem.tags);
|
|
221
|
+
}
|
|
222
|
+
return [...new Set(usedTags)];
|
|
359
223
|
};
|
|
360
|
-
var skip = (message) => message + " " + chalk2.gray("[\u8DF3\u8FC7]");
|
|
361
224
|
var normalizePath = (uri) => {
|
|
362
225
|
return uri.replace(/:([a-z0-9_?]+)/gi, (_, $1) => {
|
|
363
226
|
return `{${$1.replace(/[?]/g, "")}}`;
|
|
364
227
|
});
|
|
365
228
|
};
|
|
366
229
|
var getTagByFilename = (file) => {
|
|
367
|
-
return
|
|
230
|
+
return path2.basename(file).replace(/\..+$/, "");
|
|
368
231
|
};
|
|
369
232
|
|
|
370
|
-
// src/
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
spinner.text + " " + chalk3.red(`[${e.message}]`)
|
|
414
|
-
);
|
|
415
|
-
return;
|
|
233
|
+
// src/lib/generate-document.ts
|
|
234
|
+
import logSymbols from "log-symbols";
|
|
235
|
+
|
|
236
|
+
// src/lib/append-tag.ts
|
|
237
|
+
var appendTag = (document, usedTags) => {
|
|
238
|
+
const tags = document.tags ||= [];
|
|
239
|
+
const definedTags = tags.map((item) => item.name);
|
|
240
|
+
const undefinedTags = usedTags.filter((tag) => !definedTags.includes(tag)).sort();
|
|
241
|
+
for (const tag of undefinedTags) {
|
|
242
|
+
tags.push({ name: tag });
|
|
243
|
+
}
|
|
244
|
+
return undefinedTags;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/lib/generate-document.ts
|
|
248
|
+
var generateDocument = async (config) => {
|
|
249
|
+
const spinner = new Listr([], { concurrent: false, exitOnError: true });
|
|
250
|
+
spinner.add({
|
|
251
|
+
title: i18n.t("openapi.initialize"),
|
|
252
|
+
task: async (ctx) => {
|
|
253
|
+
ctx.document = await initializeDocument(config.docs);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
spinner.add({
|
|
257
|
+
title: i18n.t("openapi.search_routers_files"),
|
|
258
|
+
task: async (ctx) => {
|
|
259
|
+
ctx.files = await pathToFiles(config.routers);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
spinner.add({
|
|
263
|
+
title: i18n.t("openapi.parse_routers"),
|
|
264
|
+
task: async (ctx) => {
|
|
265
|
+
ctx.usedTags = await parseFiles(ctx.document, ctx.files);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
spinner.add({
|
|
269
|
+
title: i18n.t("openapi.add_tag"),
|
|
270
|
+
task: (ctx, task) => {
|
|
271
|
+
const undefinedTags = appendTag(ctx.document, ctx.usedTags);
|
|
272
|
+
if (undefinedTags.length) {
|
|
273
|
+
task.title += " " + chalk.green(undefinedTags.join(" "));
|
|
274
|
+
} else {
|
|
275
|
+
task.skip();
|
|
416
276
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
spinner.add({
|
|
280
|
+
title: i18n.t("openapi.hand_fix_documentation"),
|
|
281
|
+
skip: !config.fix,
|
|
282
|
+
task: async (ctx) => {
|
|
283
|
+
await config.fix(ctx.document);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
spinner.add({
|
|
287
|
+
title: i18n.t("openapi.optimize_parameter"),
|
|
288
|
+
task: (ctx) => {
|
|
289
|
+
methodParameterToPathParameter(ctx.document);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
spinner.add({
|
|
293
|
+
title: i18n.t("openapi.save_to_file"),
|
|
294
|
+
skip: config.saveToFile === false,
|
|
295
|
+
task: async (ctx, task) => {
|
|
296
|
+
if (config.saveToFile === false) return;
|
|
297
|
+
const result = await saveToFile(ctx.document, config.saveToFile, config.fileMode);
|
|
298
|
+
task.title += " " + path3.relative(process.cwd(), result.dest) + chalk.gray(` [${result.size}]`);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
spinner.add({
|
|
302
|
+
title: i18n.t("openapi.validate"),
|
|
303
|
+
task: async (ctx, task) => {
|
|
304
|
+
const result = ctx.validateResult = await validateOpenapi(ctx.document);
|
|
305
|
+
const summary = [];
|
|
306
|
+
if (result.errors.length) {
|
|
307
|
+
summary.push(i18n.t("openapi.has_error", { count: result.errors.length }));
|
|
308
|
+
}
|
|
309
|
+
if (result.warnings.length) {
|
|
310
|
+
summary.push(i18n.t("openapi.has_warning", { count: result.warnings.length }));
|
|
422
311
|
}
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
result.warnings.forEach((item) => {
|
|
426
|
-
spinner.warn(formatValidateMessage(item));
|
|
427
|
-
});
|
|
312
|
+
if (summary.length) {
|
|
313
|
+
task.title += " " + chalk.yellow(summary.join(" & "));
|
|
428
314
|
}
|
|
429
|
-
}
|
|
430
|
-
);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
const context = await spinner.run({});
|
|
318
|
+
const { errors, warnings } = context.validateResult;
|
|
319
|
+
for (const error of errors) {
|
|
320
|
+
console.log(` ${logSymbols.error} ${formatValidateMessage(error)}`);
|
|
321
|
+
}
|
|
322
|
+
for (const warning of warnings) {
|
|
323
|
+
console.log(` ${logSymbols.warning} ${formatValidateMessage(warning)}`);
|
|
324
|
+
}
|
|
325
|
+
return JSON.parse(JSON.stringify(context.document));
|
|
431
326
|
};
|
|
432
327
|
var formatValidateMessage = (item) => {
|
|
433
328
|
let pathname = item.path.length ? item.path.join(".") : "";
|
|
434
329
|
return `[${pathname || "."}] ${item.message}`;
|
|
435
330
|
};
|
|
331
|
+
|
|
332
|
+
// src/openapi.ts
|
|
333
|
+
var commandName = "openapi";
|
|
334
|
+
var openapi = (options) => {
|
|
335
|
+
return middleware.console({
|
|
336
|
+
fn: async (ctx, next) => {
|
|
337
|
+
if (ctx.input.command !== commandName) return next();
|
|
338
|
+
ctx.commandMatched = true;
|
|
339
|
+
await generateDocument(options);
|
|
340
|
+
},
|
|
341
|
+
help: {
|
|
342
|
+
onDocument(doc) {
|
|
343
|
+
doc[commandName] = { summary: i18n2.t("openapi.help_summary") };
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/i18n/locales/zh-cn.ts
|
|
350
|
+
import { i18n as i18n3 } from "@aomex/core";
|
|
351
|
+
i18n3.register("zh_CN", "openapi", {
|
|
352
|
+
initialize: "\u521D\u59CB\u5316\u6587\u6863",
|
|
353
|
+
search_routers_files: "\u641C\u7D22\u8DEF\u7531\u6587\u4EF6",
|
|
354
|
+
parse_routers: "\u89E3\u6790\u8DEF\u7531",
|
|
355
|
+
add_tag: "\u589E\u52A0\u6807\u7B7E",
|
|
356
|
+
hand_fix_documentation: "\u624B\u52A8\u4FEE\u590D\u6587\u6863",
|
|
357
|
+
optimize_parameter: "\u4F18\u5316\u53C2\u6570",
|
|
358
|
+
save_to_file: "\u4FDD\u5B58\u5230\u6587\u4EF6",
|
|
359
|
+
validate: "\u9A8C\u8BC1",
|
|
360
|
+
help_summary: "openapi v3 \u6587\u6863\u751F\u6210\u5668",
|
|
361
|
+
has_error: "\u5171{{count}}\u6761\u62A5\u9519",
|
|
362
|
+
has_warning: "\u5171{{count}}\u6761\u8B66\u544A"
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// src/i18n/locales/en-us.ts
|
|
366
|
+
import { i18n as i18n4 } from "@aomex/core";
|
|
367
|
+
i18n4.register("en_US", "openapi", {
|
|
368
|
+
initialize: "initialize document",
|
|
369
|
+
search_routers_files: "search web routers files",
|
|
370
|
+
parse_routers: "parse routers",
|
|
371
|
+
add_tag: "append tags",
|
|
372
|
+
hand_fix_documentation: "fix documentation by manual",
|
|
373
|
+
optimize_parameter: "optimize parameters",
|
|
374
|
+
save_to_file: "save to file",
|
|
375
|
+
validate: "validate",
|
|
376
|
+
help_summary: "openapi v3 documentation generator",
|
|
377
|
+
has_error: "total {{count}} errors",
|
|
378
|
+
has_warning: "total {{count}} warnings"
|
|
379
|
+
});
|
|
436
380
|
export {
|
|
437
381
|
generateDocument,
|
|
438
|
-
|
|
382
|
+
initializeDocument,
|
|
383
|
+
methodParameterToPathParameter,
|
|
384
|
+
methodToVerb,
|
|
385
|
+
methods,
|
|
386
|
+
openapi,
|
|
387
|
+
parseFiles,
|
|
388
|
+
saveToFile,
|
|
389
|
+
validateOpenapi
|
|
439
390
|
};
|
|
440
391
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openapi.ts","../src/openapi-to-help.ts","../src/generate-document.ts","../src/lib/parameter.ts","../src/lib/method-to-verb.ts","../src/lib/remove-duplicate-schema.ts","../src/lib/validate.ts"],"sourcesContent":["import EventEmitter from 'node:events';\nimport { chain, middleware } from '@aomex/core';\nimport { chalk } from '@aomex/internal-tools';\nimport ora, { type Ora } from 'ora';\nimport { openapiToHelp } from './openapi-to-help';\nimport { generateDocument, type OpenapiOptions } from './generate-document';\nimport type { OpenapiValidateResult, OpenapiValidateResultItem } from './lib';\n\nexport const openapi = (\n options: Omit<OpenapiOptions, 'emitter'> & {\n renderWarnings?: boolean;\n commandName?: string;\n showInHelp?: boolean;\n summary?: string;\n description?: string;\n },\n) => {\n const commandName = options.commandName || 'openapi';\n\n return chain.console\n .mount(\n openapiToHelp(\n commandName,\n options.summary,\n options.description,\n options.showInHelp,\n ),\n )\n .mount(\n middleware.console(async (ctx, next) => {\n if (ctx.request.command !== commandName) return next();\n ctx.response.commandMatched = true;\n const emitter = new EventEmitter();\n const spinner: Ora = ora();\n\n emitter\n .on('msg', (msg) => {\n if (spinner.isSpinning) spinner.succeed();\n spinner.start(msg);\n })\n .on('replace', (msg) => {\n spinner.text = msg;\n });\n\n let result: OpenapiValidateResult,\n hasError: boolean = false,\n hasWarning: boolean = false;\n try {\n result = (await generateDocument({ ...options, emitter })).result;\n hasError = !!result.errors.length;\n hasWarning = !!result.warnings.length;\n const summary: string[] = [];\n hasError && summary.push(`${result.errors.length}条错误`);\n hasWarning && summary.push(`${result.warnings.length}条警告`);\n\n let msg = spinner.text;\n summary.length && (msg += ' ' + chalk.yellow(summary.join(',')));\n if (hasError) {\n spinner.fail(msg);\n } else if (hasWarning) {\n spinner.warn(msg);\n } else {\n spinner.succeed();\n }\n } catch (e) {\n spinner.fail(\n spinner.text + ' ' + chalk.red(`[${(e as Error).message}]`),\n );\n return;\n }\n\n if (hasError) {\n spinner.indent = 2;\n result.errors.forEach((item) => {\n spinner.fail(formatValidateMessage(item));\n });\n }\n\n if (options.renderWarnings && hasWarning) {\n spinner.indent = 2;\n result.warnings.forEach((item) => {\n spinner.warn(formatValidateMessage(item));\n });\n }\n }),\n );\n};\n\nconst formatValidateMessage = (item: OpenapiValidateResultItem) => {\n let pathname = item.path.length ? item.path.join('.') : '';\n return `[${pathname || '.'}] ${item.message}`;\n};\n","import { HelpMiddleware, scriptName } from '@aomex/console';\nimport { middleware } from '@aomex/core';\nimport { chalk } from '@aomex/internal-tools';\n\nexport const openapiToHelp = (\n commandName: string,\n summary?: string,\n description?: string,\n showInHelp: boolean = true,\n): HelpMiddleware =>\n middleware.help(async (ctx, next) => {\n return ctx.cli.config({\n all(yargs) {\n yargs.command(\n chalk.yellow(commandName),\n summary || 'Generate openapi v3 documentation',\n );\n },\n detailCommand: () => showInHelp && ctx.request.command === commandName,\n detail(yargs) {\n yargs.usage(\n `${scriptName} ${commandName} [options]${\n description ? '\\n\\n' + chalk.bold(description) : ''\n }`,\n );\n },\n next,\n });\n });\n","import EventEmitter from 'node:events';\nimport type { Mode } from 'node:fs';\nimport { readPackageUp } from 'read-pkg-up';\nimport snakeCase from 'lodash.snakecase';\nimport { Chain, OpenAPI } from '@aomex/core';\nimport { bytes, chalk, sleep } from '@aomex/internal-tools';\nimport {\n type PathToFileOptions,\n fileToModules,\n pathToFiles,\n} from '@aomex/internal-file-import';\nimport { METHOD, WebMiddleware } from '@aomex/web';\nimport { Router } from '@aomex/router';\nimport path from 'node:path';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport yaml from 'yaml';\nimport {\n methodParameterToPathParameter,\n parameterToComponent,\n} from './lib/parameter';\nimport {\n methodToVerb,\n type OpenapiValidateResult,\n validate,\n removeDuplicateSchema,\n} from './lib';\n\nexport interface OpenapiOptions {\n /**\n * Web api routers\n */\n routers: PathToFileOptions;\n /**\n * Openapi basic information\n * @see OpenApiDocs\n */\n docs?: Omit<OpenAPI.Document, 'paths' | 'openapi' | 'info'> & {\n openapi?: `3.0.${0 | 1 | 2 | 3}`;\n info?: Partial<OpenAPI.Document['info']>;\n };\n /**\n * Save document to specific file (`*.yaml`|`*.json`). Defaults `openapi.json`\n */\n output?: false | string;\n /**\n * File mode. Defaults according system\n * @see OpenapiOptions.output\n */\n fileMode?: Mode;\n /**\n * Format JSON document to human readable. Defaults `false`\n */\n prettyJson?: boolean;\n /**\n * Fix the document by hand after the full document is generated\n */\n fix?: (data: OpenAPI.Document) => void;\n /**\n * Log emitter\n */\n emitter: EventEmitter;\n}\n\nexport const generateDocument = async (\n config: OpenapiOptions,\n): Promise<{\n document: OpenAPI.Document;\n result: OpenapiValidateResult;\n}> => {\n const emitter = config.emitter || new EventEmitter();\n let msg = '';\n\n emitter.emit('start');\n emitter.emit('msg', '初始化');\n const document: OpenAPI.Document = JSON.parse(\n JSON.stringify(config.docs || {}),\n );\n\n {\n document.openapi ||= '3.0.3';\n document.tags ||= [];\n document.info ||= { title: '', version: '' };\n document.paths = {};\n document.info.title ||=\n (await readPackageUp())?.packageJson.name || 'API documentation';\n document.info.version ||=\n (await readPackageUp())?.packageJson.version || '0.0.0';\n }\n\n emitter.emit('msg', (msg = '搜索路由文件'));\n const files = await pathToFiles(config.routers);\n emitter.emit('msg', (msg = '解析路由'));\n const usedTags: string[] = [];\n for (const file of files) {\n emitter.emit(\n 'replace',\n msg +\n ' ' +\n chalk.gray(\n path\n .relative(process.cwd(), file)\n .split(path.sep)\n .join(path.posix.sep),\n ),\n );\n await sleep(50);\n\n const routers = await fileToModules<Router>(\n [file],\n (item) => !!item && item instanceof Router,\n );\n for (const router of routers) {\n const groupMiddlewareList = Chain.flatten(router['chain']);\n const builders = router['builders'];\n\n for (const builder of builders) {\n for (const uri of builder.uris) {\n const pathItem = (document.paths[normalizePath(uri)] ||= {});\n let methods = builder.methods;\n\n if (methods.includes(METHOD.GET) && methods.includes(METHOD.HEAD)) {\n methods = methods.filter((method) => method !== 'HEAD');\n }\n\n for (const method of methods) {\n const methodItem: OpenAPI.OperationObject = (pathItem[\n method.toLowerCase() as `${Lowercase<METHOD>}`\n ] = {\n responses: {},\n ...builder.docs,\n });\n\n for (const middleware of groupMiddlewareList.concat(\n Chain.flatten(builder.chain),\n )) {\n if (middleware instanceof WebMiddleware) {\n middleware.toDocument({\n document,\n pathItem,\n methodName: method,\n methodItem,\n });\n }\n }\n\n methodItem.tags ||= [getTagByFilename(file)];\n methodItem.operationId ||= snakeCase(\n methodToVerb(method, uri) + ' ' + uri.replaceAll(':', '_by_'),\n );\n\n if (method === METHOD.POST) {\n // @ts-expect-error against warning\n methodItem['x-codegen-request-body-name'] = 'body';\n }\n\n if (Object.keys(methodItem.responses).length === 0) {\n methodItem.responses = {\n default: {\n description: '',\n },\n };\n }\n\n usedTags.push(...methodItem.tags!);\n }\n }\n }\n }\n }\n emitter.emit('replace', msg);\n\n {\n const tags = document.tags!;\n const definedTags = tags.map((item) => item.name);\n for (const tag of [...new Set(usedTags)].sort()) {\n if (!definedTags.includes(tag)) {\n emitter.emit('msg', (msg = `增加标签:${tag}`));\n tags.push({ name: tag });\n }\n }\n }\n\n {\n emitter.emit('msg', (msg = '手动修复文档内容'));\n if (config.fix) {\n config.fix(document);\n } else {\n emitter.emit('replace', skip(msg));\n }\n }\n\n {\n emitter.emit('msg', (msg = '优化参数'));\n methodParameterToPathParameter(document);\n parameterToComponent(document);\n }\n\n {\n emitter.emit('msg', (msg = '优化结构'));\n removeDuplicateSchema(document);\n }\n\n {\n emitter.emit('msg', (msg = '保存到文件'));\n let distFile: typeof config.output =\n config.output === false ? false : config.output || 'openapi.json';\n if (distFile) {\n distFile = path.resolve(distFile);\n await mkdir(path.dirname(distFile), {\n recursive: true,\n });\n\n const content = ['.yml', '.yaml'].includes(path.extname(distFile))\n ? yaml.stringify(document)\n : JSON.stringify(document, null, config.prettyJson ? 2 : undefined);\n\n await writeFile(distFile, content, {\n mode: config.fileMode,\n });\n const size = bytes(Buffer.byteLength(content), { unitSeparator: '' });\n emitter.emit(\n 'replace',\n msg +\n ': ' +\n path.relative(process.cwd(), distFile) +\n chalk.gray(` [${size}]`),\n true,\n );\n } else {\n emitter.emit('replace', skip(msg));\n }\n }\n\n let result: OpenapiValidateResult;\n {\n emitter.emit('msg', (msg = '验证'));\n result = await validate(document);\n }\n\n return {\n document: JSON.parse(JSON.stringify(document)),\n result: {\n errors: result.errors || [],\n warnings: result.warnings || [],\n },\n };\n};\n\nconst skip = (message: string) => message + ' ' + chalk.gray('[跳过]');\n\nconst normalizePath = (uri: string) => {\n return uri.replace(/:([a-z0-9_?]+)/gi, (_, $1) => {\n return `{${$1.replace(/[?]/g, '')}}`;\n });\n};\n\nconst getTagByFilename = (file: string) => {\n return path.basename(file).replace(/\\..+$/, '');\n};\n","import type { OpenAPI } from '@aomex/core';\nimport { METHOD } from '@aomex/web';\n\nexport const parameterToComponent = (document: OpenAPI.Document) => {\n const parametersStringify: string[] = [];\n const parametersRef = new Map<string, string | ((ref: string) => void)>();\n let count = 0;\n document.components ||= {};\n document.components.parameters ||= {};\n\n const parser = (\n parameter: OpenAPI.ParameterObject | OpenAPI.ReferenceObject,\n index: number,\n arr: (OpenAPI.ParameterObject | OpenAPI.ReferenceObject)[],\n ) => {\n if ('$ref' in parameter) return;\n const str = JSON.stringify(parameter);\n const replace = (ref: string) => {\n arr[index] = {\n $ref: '#/components/parameters/' + ref,\n };\n };\n if (parametersStringify.includes(str)) {\n let ref = parametersRef.get(str)!;\n if (typeof ref === 'function') {\n const firstReplace = ref;\n const name = (parameter as OpenAPI.ParameterObject).name;\n ref = document.components!.parameters![name]\n ? name + '_' + ++count\n : name;\n document.components!.parameters![ref] = parameter;\n parametersRef.set(str, ref);\n firstReplace(ref);\n }\n replace(ref);\n } else {\n parametersStringify.push(str);\n parametersRef.set(str, replace);\n }\n };\n\n for (const path of Object.values(document.paths)) {\n path!.parameters?.forEach(parser);\n for (const method of methods) {\n const methodItem = path![method];\n if (!methodItem || !methodItem.parameters) continue;\n methodItem.parameters.forEach(parser);\n }\n }\n\n if (Object.keys(document.components.parameters).length === 0) {\n delete document.components.parameters;\n }\n\n if (Object.keys(document.components).length === 0) {\n delete document.components;\n }\n};\n\nexport const methodParameterToPathParameter = (document: OpenAPI.Document) => {\n pathLoop: for (const path of Object.values(document.paths)) {\n const parametersCallback: Record<string, Function[]> = {};\n let index = 0;\n for (const method of methods) {\n const methodItem = path![method];\n if (!methodItem) continue;\n if (!methodItem.parameters?.length) continue pathLoop;\n ++index;\n methodItem.parameters.forEach((parameter, index, arr) => {\n const str = JSON.stringify(parameter);\n // Make sure it's unique\n parameter = arr[index] = JSON.parse(str);\n parametersCallback[str] ||= [];\n parametersCallback[str]!.push(() => {\n arr.splice(\n arr.findIndex((item) => item === parameter),\n 1,\n );\n if (!arr.length) {\n delete methodItem.parameters;\n }\n });\n });\n }\n if (index < 2) continue pathLoop;\n Object.entries(parametersCallback).forEach(([key, callbacks]) => {\n if (callbacks.length !== index) return;\n path!.parameters ||= [];\n path!.parameters.push(JSON.parse(key));\n callbacks.forEach((callback) => callback());\n });\n if (path!.parameters && !path!.parameters.length) {\n delete path!.parameters;\n }\n }\n};\n\nconst methods = Object.values(METHOD).map((method) =>\n method.toLowerCase(),\n) as OpenAPI.HttpMethods[];\n","export const methodToVerb = (method: string, uri: string) => {\n method = method.toLowerCase();\n\n if (method === 'get' && !uri.includes(':')) return 'list';\n if (method === 'post') return 'create';\n if (method === 'put') return 'replace';\n if (method === 'patch') return 'update';\n return method;\n};\n","import { OpenAPI } from '@aomex/core';\n\nexport const removeDuplicateSchema = (document: OpenAPI.Document) => {\n document.components ||= {};\n document.components.schemas ||= {};\n const schemas = document.components.schemas;\n\n (function loopSearch(docs: Record<string, any>) {\n if (typeof docs !== 'object') return;\n Object.entries(docs).forEach(([key, value]) => {\n if (value === schemas) return;\n if (!isValidSchemaObject(value)) {\n return loopSearch(value);\n }\n const ref = value['x-schema-ref'];\n docs[key] = <OpenAPI.ReferenceObject>{\n $ref: '#/components/schemas/' + ref,\n };\n if (!schemas[ref]) {\n Reflect.deleteProperty(value, 'x-schema-ref');\n schemas[ref] = value;\n }\n });\n })(document);\n\n if (Object.keys(document.components.schemas).length === 0) {\n delete document.components.schemas;\n }\n if (Object.keys(document.components).length === 0) {\n delete document.components;\n }\n};\n\nconst isValidSchemaObject = (\n value: any,\n): value is OpenAPI.SchemaObject & { 'x-schema-ref': string } => {\n return (\n typeof value === 'object' && !!value['type'] && !!value['x-schema-ref']\n );\n};\n","import type { OpenAPI } from '@aomex/core';\nimport stoplight, { type RulesetDefinition } from '@stoplight/spectral-core';\nimport { oas } from '@stoplight/spectral-rulesets';\n\n// Inline package `@stoplight/types`\nenum DiagnosticSeverity {\n Error = 0,\n Warning = 1,\n Information = 2,\n Hint = 3,\n}\n\nconst spectral = new stoplight.Spectral();\nspectral.setRuleset({\n extends: oas as RulesetDefinition,\n // https://github.com/stoplightio/spectral/blob/develop/packages/rulesets/src/oas/index.ts\n rules: {\n 'info-contact': 'off',\n 'info-description': 'off',\n },\n});\n\nexport interface OpenapiValidateResultItem {\n path: string[];\n message: string;\n}\n\nexport interface OpenapiValidateResult {\n errors: OpenapiValidateResultItem[];\n warnings: OpenapiValidateResultItem[];\n}\n\nexport const validate = async (document: OpenAPI.Document) => {\n const result: OpenapiValidateResult = {\n warnings: [],\n errors: [],\n };\n const originResult = await spectral.run(\n document as unknown as Record<string, unknown>,\n );\n originResult.forEach((item) => {\n result[\n item.severity === DiagnosticSeverity.Error ? 'errors' : 'warnings'\n ].push({\n path: item.path.map(String),\n message: item.message,\n });\n });\n return result;\n};\n"],"mappings":";AAAA,OAAOA,mBAAkB;AACzB,SAAS,OAAO,cAAAC,mBAAkB;AAClC,SAAS,SAAAC,cAAa;AACtB,OAAO,SAAuB;;;ACH9B,SAAyB,kBAAkB;AAC3C,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AAEf,IAAM,gBAAgB,CAC3B,aACA,SACA,aACA,aAAsB,SAEtB,WAAW,KAAK,OAAO,KAAK,SAAS;AACnC,SAAO,IAAI,IAAI,OAAO;AAAA,IACpB,IAAI,OAAO;AACT,YAAM;AAAA,QACJ,MAAM,OAAO,WAAW;AAAA,QACxB,WAAW;AAAA,MACb;AAAA,IACF;AAAA,IACA,eAAe,MAAM,cAAc,IAAI,QAAQ,YAAY;AAAA,IAC3D,OAAO,OAAO;AACZ,YAAM;AAAA,QACJ,GAAG,UAAU,IAAI,WAAW,aAC1B,cAAc,SAAS,MAAM,KAAK,WAAW,IAAI,EACnD;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,EACF,CAAC;AACH,CAAC;;;AC5BH,OAAO,kBAAkB;AAEzB,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AACtB,SAAS,aAAsB;AAC/B,SAAS,OAAO,SAAAC,QAAO,aAAa;AACpC;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAAC,SAAQ,q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AAK,sBAAsB,IAAI,CAAC;AAAA,QAC1C,CAAC;AAAA,MACH;AAEA,UAAI,QAAQ,kBAAkB,YAAY;AACxC,gBAAQ,SAAS;AACjB,eAAO,SAAS,QAAQ,CAAC,SAAS;AAChC,kBAAQ,KAAK,sBAAsB,IAAI,CAAC;AAAA,QAC1C,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAAA,EACH;AACJ;AAEA,IAAM,wBAAwB,CAAC,SAAoC;AACjE,MAAI,WAAW,KAAK,KAAK,SAAS,KAAK,KAAK,KAAK,GAAG,IAAI;AACxD,SAAO,IAAI,YAAY,GAAG,KAAK,KAAK,OAAO;AAC7C;","names":["EventEmitter","middleware","chalk","chalk","METHOD","path","index","chalk","methods","METHOD","middleware","middleware","EventEmitter","chalk"]}
|
|
1
|
+
{"version":3,"sources":["../src/openapi.ts","../src/lib/generate-document.ts","../src/lib/validate-openapi.ts","../src/lib/methods.ts","../src/lib/method-parameter-to-path-parameter.ts","../src/lib/save-to-file.ts","../src/lib/initialize-document.ts","../src/lib/parse-files.ts","../src/lib/method-to-verb.ts","../src/lib/append-tag.ts","../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts"],"sourcesContent":["import { i18n, middleware } from '@aomex/core';\nimport type { ConsoleMiddleware } from '@aomex/console';\nimport { generateDocument, type OpenapiOptions } from './lib/generate-document';\n\nconst commandName = 'openapi';\n\nexport const openapi = (options: OpenapiOptions): ConsoleMiddleware => {\n return middleware.console({\n fn: async (ctx, next) => {\n if (ctx.input.command !== commandName) return next();\n ctx.commandMatched = true;\n await generateDocument(options);\n },\n help: {\n onDocument(doc) {\n doc[commandName] = { summary: i18n.t('openapi.help_summary') };\n },\n },\n });\n};\n","import type { Mode } from 'node:fs';\nimport { OpenAPI, i18n } from '@aomex/core';\nimport { chalk } from '@aomex/internal-tools';\nimport { pathToFiles, type GlobPathOptions } from '@aomex/internal-file-import';\nimport path from 'node:path';\nimport {\n validateOpenapi,\n type OpenapiValidateResult,\n type OpenapiValidateResultItem,\n} from './validate-openapi';\nimport { methodParameterToPathParameter } from './method-parameter-to-path-parameter';\nimport { saveToFile } from './save-to-file';\nimport { initializeDocument } from './initialize-document';\nimport { Listr } from 'listr2';\nimport { parseFiles } from './parse-files';\nimport logSymbols from 'log-symbols';\nimport { appendTag } from './append-tag';\n\nexport interface OpenapiOptions {\n /**\n * http接口路由文件\n */\n routers: GlobPathOptions;\n /**\n * Openapi基础信息\n */\n docs?: Omit<OpenAPI.Document, 'paths' | 'openapi' | 'info'> & {\n openapi?: `3.0.${0 | 1 | 2 | 3}`;\n info?: Partial<OpenAPI.Document['info']>;\n };\n /**\n * 保存到指定文件。默认值:`openapi.json`\n * - `*.json` 保存为JSON格式\n * - `*.yml` 保存为YAML格式\n * - `*.yaml` 保存为YAML格式\n */\n saveToFile?: false | string;\n /**\n * 设置保存文件的系统权限。\n */\n fileMode?: Mode;\n /**\n * 手动修复文档内容\n */\n fix?: (data: OpenAPI.Document) => void | Promise<void>;\n}\n\ninterface SpinnerContext {\n document: OpenAPI.Document;\n files: string[];\n usedTags: string[];\n validateResult: OpenapiValidateResult;\n}\n\nexport const generateDocument = async (\n config: OpenapiOptions,\n): Promise<OpenAPI.Document> => {\n const spinner = new Listr<SpinnerContext>([], { concurrent: false, exitOnError: true });\n\n spinner.add({\n title: i18n.t('openapi.initialize'),\n task: async (ctx) => {\n ctx.document = await initializeDocument(config.docs);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.search_routers_files'),\n task: async (ctx) => {\n ctx.files = await pathToFiles(config.routers);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.parse_routers'),\n task: async (ctx) => {\n ctx.usedTags = await parseFiles(ctx.document, ctx.files);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.add_tag'),\n task: (ctx, task) => {\n const undefinedTags = appendTag(ctx.document, ctx.usedTags);\n if (undefinedTags.length) {\n task.title += ' ' + chalk.green(undefinedTags.join(' '));\n } else {\n task.skip();\n }\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.hand_fix_documentation'),\n skip: !config.fix,\n task: async (ctx) => {\n await config.fix!(ctx.document);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.optimize_parameter'),\n task: (ctx) => {\n methodParameterToPathParameter(ctx.document);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.save_to_file'),\n skip: config.saveToFile === false,\n task: async (ctx, task) => {\n if (config.saveToFile === false) return;\n const result = await saveToFile(ctx.document, config.saveToFile, config.fileMode);\n task.title +=\n ' ' + path.relative(process.cwd(), result.dest) + chalk.gray(` [${result.size}]`);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.validate'),\n task: async (ctx, task) => {\n const result = (ctx.validateResult = await validateOpenapi(ctx.document));\n const summary: string[] = [];\n\n if (result.errors.length) {\n summary.push(i18n.t('openapi.has_error', { count: result.errors.length }));\n }\n if (result.warnings.length) {\n summary.push(i18n.t('openapi.has_warning', { count: result.warnings.length }));\n }\n if (summary.length) {\n task.title += ' ' + chalk.yellow(summary.join(' & '));\n }\n },\n });\n\n const context = await spinner.run({} as SpinnerContext);\n\n const { errors, warnings } = context.validateResult;\n for (const error of errors) {\n console.log(` ${logSymbols.error} ${formatValidateMessage(error)}`);\n }\n for (const warning of warnings) {\n console.log(` ${logSymbols.warning} ${formatValidateMessage(warning)}`);\n }\n\n return JSON.parse(JSON.stringify(context.document));\n};\n\nconst formatValidateMessage = (item: OpenapiValidateResultItem) => {\n let pathname = item.path.length ? item.path.join('.') : '';\n return `[${pathname || '.'}] ${item.message}`;\n};\n","import type { OpenAPI } from '@aomex/core';\nimport stoplight, { type RulesetDefinition } from '@stoplight/spectral-core';\nimport { oas } from '@stoplight/spectral-rulesets';\n\n// Inline package `@stoplight/types`\nenum DiagnosticSeverity {\n Error = 0,\n Warning = 1,\n Information = 2,\n Hint = 3,\n}\n\nconst spectral = new stoplight.Spectral();\nspectral.setRuleset({\n extends: oas as RulesetDefinition,\n // https://github.com/stoplightio/spectral/blob/develop/packages/rulesets/src/oas/index.ts\n rules: {\n 'info-contact': 'off',\n 'info-description': 'off',\n },\n});\n\nexport interface OpenapiValidateResultItem {\n path: string[];\n message: string;\n}\n\nexport interface OpenapiValidateResult {\n errors: OpenapiValidateResultItem[];\n warnings: OpenapiValidateResultItem[];\n}\n\nexport const validateOpenapi = async (document: OpenAPI.Document) => {\n const result: OpenapiValidateResult = {\n warnings: [],\n errors: [],\n };\n const originResult = await spectral.run(document as unknown as Record<string, unknown>);\n originResult.forEach((item) => {\n result[item.severity === DiagnosticSeverity.Error ? 'errors' : 'warnings'].push({\n path: item.path.map(String),\n message: item.message,\n });\n });\n return result;\n};\n","export const methods = <const>[\n 'get',\n 'post',\n 'put',\n 'patch',\n 'delete',\n 'options',\n 'head',\n 'trace',\n];\n","import type { OpenAPI } from '@aomex/core';\nimport { methods } from './methods';\n\n/**\n * 同一个路径下,所有方法都有相同的parameter时,可以往上提取,这样能减小生成产物\n */\nexport const methodParameterToPathParameter = (document: OpenAPI.Document) => {\n pathLoop: for (const path of Object.values(document.paths)) {\n const parametersHandler: Record<string, Function[]> = {};\n let methodCounter = 0;\n for (const method of methods) {\n const methodItem = path![method];\n if (!methodItem) continue;\n if (!methodItem.parameters?.length) continue pathLoop;\n ++methodCounter;\n methodItem.parameters.forEach((parameter, index, arr) => {\n const uniqueKey = JSON.stringify(parameter);\n // 确保是唯一的\n parameter = arr[index] = JSON.parse(uniqueKey);\n const handler = () => {\n arr.splice(\n arr.findIndex((item) => item === parameter),\n 1,\n );\n if (!arr.length) {\n delete methodItem.parameters;\n }\n };\n parametersHandler[uniqueKey] ||= [];\n parametersHandler[uniqueKey]!.push(handler);\n });\n }\n\n if (methodCounter < 2) continue pathLoop;\n\n Object.entries(parametersHandler).forEach(([uniqueKey, handlers]) => {\n if (handlers.length !== methodCounter) return;\n path!.parameters ||= [];\n path!.parameters.push(JSON.parse(uniqueKey));\n handlers.forEach((fn) => fn());\n });\n if (path!.parameters && !path!.parameters.length) {\n delete path!.parameters;\n }\n }\n};\n","import path from 'node:path';\nimport { mkdir, writeFile } from 'node:fs/promises';\nimport YAML from 'yaml';\nimport { bytes } from '@aomex/internal-tools';\nimport type { OpenAPI } from '@aomex/core';\nimport type { Mode } from 'node:fs';\n\nexport const saveToFile = async (\n document: OpenAPI.Document,\n filename?: string,\n fileMode?: Mode,\n) => {\n const dest = path.resolve(filename || 'openapi.json');\n const content = ['.yml', '.yaml'].includes(path.extname(dest))\n ? YAML.stringify(document)\n : JSON.stringify(document);\n const size = bytes(Buffer.byteLength(content), { unitSeparator: '' });\n\n await mkdir(path.dirname(dest), { recursive: true });\n await writeFile(dest, content, { mode: fileMode });\n\n return { dest, size };\n};\n","import type { OpenAPI } from '@aomex/core';\nimport type { OpenapiOptions } from './generate-document';\nimport { readPackageUp } from 'read-package-up';\n\nexport const initializeDocument = async (basic?: OpenapiOptions['docs']) => {\n const document: OpenAPI.Document = JSON.parse(JSON.stringify(basic || {}));\n document.openapi ||= '3.0.3';\n document.tags ||= [];\n document.info ||= { title: '', version: '' };\n document.paths = {};\n document.info.title ||= (await readPackageUp())?.packageJson.name || 'OpenAPI';\n document.info.version ||= (await readPackageUp())?.packageJson.version || '0.0.0';\n return document;\n};\n","import { flattenMiddlewareToken, type OpenAPI } from '@aomex/core';\nimport { getFileValues } from '@aomex/internal-file-import';\nimport { Router } from '@aomex/router';\nimport { WebMiddleware, WebRequest, type OpenApiInjector } from '@aomex/web';\nimport path from 'node:path';\nimport { methodToVerb } from './method-to-verb';\nimport snakeCase from 'lodash.snakecase';\n\nexport const parseFiles = async (document: OpenAPI.Document, files: string[]) => {\n const usedTags: string[] = [];\n\n const data: {\n pathName: string;\n pathItem: OpenAPI.PathItemObject;\n methodName: `${Lowercase<WebRequest['method']>}`;\n methodItem: OpenAPI.OperationObject;\n injector: OpenApiInjector;\n file: string;\n uri: string;\n }[] = [];\n\n for (const file of files) {\n const routers = await getFileValues<Router>(\n [file],\n (item) => !!item && item instanceof Router,\n );\n\n for (const router of routers) {\n const groupMiddlewareList = flattenMiddlewareToken(router['middlewareChain']);\n const builders = router['builders'];\n\n for (const builder of builders) {\n const builderMiddlewareList = groupMiddlewareList\n .concat(builder['middlewareList'])\n .filter((middleware) => middleware instanceof WebMiddleware) as WebMiddleware[];\n\n for (const uri of builder['uris']) {\n const pathName = normalizePath(uri);\n const pathItem: OpenAPI.PathItemObject = (document.paths[pathName] ||= {});\n let methods = builder['methods'];\n if (methods.includes('GET') && methods.includes('HEAD')) {\n methods = methods.filter((method) => method !== 'HEAD');\n }\n\n for (const method of methods) {\n const methodName =\n method.toLowerCase() as `${Lowercase<WebRequest['method']>}`;\n const methodItem: OpenAPI.OperationObject = (pathItem[methodName] = {\n ...builder.docs,\n responses: {},\n });\n\n data.push(\n ...builderMiddlewareList.map((item) => {\n return {\n injector: item['openapi'](),\n pathItem,\n pathName,\n methodItem,\n methodName,\n file,\n uri,\n };\n }),\n );\n }\n }\n }\n }\n }\n\n for (const { injector } of data) {\n injector.onDocument?.(document);\n }\n for (const { injector, pathItem, pathName } of data) {\n injector.onPath?.(pathItem, { document, pathName });\n }\n for (const { injector, pathItem, pathName, methodItem, methodName } of data) {\n injector.onMethod?.(methodItem, {\n document,\n pathItem,\n pathName,\n methodName,\n });\n }\n for (const { injector, pathItem, pathName, methodItem, methodName } of data) {\n injector.postMethod?.(methodItem, {\n document,\n pathItem,\n pathName,\n methodName,\n });\n }\n for (const { injector, pathItem, pathName } of data) {\n injector.postPath?.(pathItem, { document, pathName });\n }\n for (const { injector } of data) {\n injector.postDocument?.(document);\n }\n\n for (const { methodItem, methodName, file, uri } of data) {\n methodItem.tags ||= [getTagByFilename(file)];\n methodItem.operationId ||= snakeCase(\n methodToVerb(methodName, uri) + ' ' + uri.replaceAll(':', '_by_'),\n );\n\n if (methodName === 'post') {\n // @ts-expect-error 防止验证警告\n methodItem['x-codegen-request-body-name'] = 'body';\n }\n\n if (!Object.keys(methodItem.responses).length) {\n methodItem.responses = { default: { description: '' } };\n }\n\n usedTags.push(...methodItem.tags!);\n }\n\n return [...new Set(usedTags)];\n};\n\nconst normalizePath = (uri: string) => {\n return uri.replace(/:([a-z0-9_?]+)/gi, (_, $1) => {\n return `{${$1.replace(/[?]/g, '')}}`;\n });\n};\n\nconst getTagByFilename = (file: string) => {\n return path.basename(file).replace(/\\..+$/, '');\n};\n","export const methodToVerb = (method: string, uri: string) => {\n method = method.toLowerCase();\n\n if (method === 'get') return uri.includes(':') ? 'retrieve' : 'list';\n if (method === 'post') return 'create';\n if (method === 'put') return 'replace';\n if (method === 'patch') return 'update';\n return method;\n};\n","import type { OpenAPI } from '@aomex/core';\n\nexport const appendTag = (document: OpenAPI.Document, usedTags: string[]) => {\n const tags = (document.tags ||= []);\n const definedTags = tags.map((item) => item.name);\n const undefinedTags = usedTags.filter((tag) => !definedTags.includes(tag)).sort();\n\n for (const tag of undefinedTags) {\n tags.push({ name: tag });\n }\n\n return undefinedTags;\n};\n","import { i18n } from '@aomex/core';\n\ni18n.register('zh_CN', 'openapi', {\n initialize: '初始化文档',\n search_routers_files: '搜索路由文件',\n parse_routers: '解析路由',\n add_tag: '增加标签',\n hand_fix_documentation: '手动修复文档',\n optimize_parameter: '优化参数',\n save_to_file: '保存到文件',\n validate: '验证',\n help_summary: 'openapi v3 文档生成器',\n has_error: '共{{count}}条报错',\n has_warning: '共{{count}}条警告',\n});\n","import { i18n } from '@aomex/core';\n\ni18n.register('en_US', 'openapi', {\n initialize: 'initialize document',\n search_routers_files: 'search web routers files',\n parse_routers: 'parse routers',\n add_tag: 'append tags',\n hand_fix_documentation: 'fix documentation by manual',\n optimize_parameter: 'optimize parameters',\n save_to_file: 'save to file',\n validate: 'validate',\n help_summary: 'openapi v3 documentation generator',\n has_error: 'total {{count}} errors',\n has_warning: 'total {{count}} warnings',\n});\n"],"mappings":";AAAA,SAAS,QAAAA,OAAM,kBAAkB;;;ACCjC,SAAkB,YAAY;AAC9B,SAAS,aAAa;AACtB,SAAS,mBAAyC;AAClD,OAAOC,WAAU;;;AC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O,IAAI,YAAY,GAAG,KAAK,KAAK,OAAO;AAC7C;;;ADpJA,IAAM,cAAc;AAEb,IAAM,UAAU,CAAC,YAA+C;AACrE,SAAO,WAAW,QAAQ;AAAA,IACxB,IAAI,OAAO,KAAK,SAAS;AACvB,UAAI,IAAI,MAAM,YAAY,YAAa,QAAO,KAAK;AACnD,UAAI,iBAAiB;AACrB,YAAM,iBAAiB,OAAO;AAAA,IAChC;AAAA,IACA,MAAM;AAAA,MACJ,WAAW,KAAK;AACd,YAAI,WAAW,IAAI,EAAE,SAASC,MAAK,EAAE,sBAAsB,EAAE;AAAA,MAC/D;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;AUnBA,SAAS,QAAAC,aAAY;AAErBA,MAAK,SAAS,SAAS,WAAW;AAAA,EAChC,YAAY;AAAA,EACZ,sBAAsB;AAAA,EACtB,eAAe;AAAA,EACf,SAAS;AAAA,EACT,wBAAwB;AAAA,EACxB,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,UAAU;AAAA,EACV,cAAc;AAAA,EACd,WAAW;AAAA,EACX,aAAa;AACf,CAAC;;;ACdD,SAAS,QAAAC,aAAY;AAErBA,MAAK,SAAS,SAAS,WAAW;AAAA,EAChC,YAAY;AAAA,EACZ,sBAAsB;AAAA,EACtB,eAAe;AAAA,EACf,SAAS;AAAA,EACT,wBAAwB;AAAA,EACxB,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACd,UAAU;AAAA,EACV,cAAc;AAAA,EACd,WAAW;AAAA,EACX,aAAa;AACf,CAAC;","names":["i18n","path","path","path","middleware","methods","path","path","i18n","i18n","i18n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/openapi",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Openapi
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Openapi文档生成工具",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -26,30 +26,29 @@
|
|
|
26
26
|
"homepage": "https://aomex.js.org",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@aomex/console": "^0.0
|
|
30
|
-
"@aomex/core": "^0.0
|
|
31
|
-
"@aomex/router": "^0.0
|
|
32
|
-
"@aomex/web": "^0.0
|
|
29
|
+
"@aomex/console": "^1.0.0",
|
|
30
|
+
"@aomex/core": "^1.0.0",
|
|
31
|
+
"@aomex/router": "^1.0.0",
|
|
32
|
+
"@aomex/web": "^1.0.0"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@stoplight/spectral-core": "^1.18.
|
|
36
|
-
"@stoplight/spectral-rulesets": "^1.
|
|
35
|
+
"@stoplight/spectral-core": "^1.18.3",
|
|
36
|
+
"@stoplight/spectral-rulesets": "^1.19.1",
|
|
37
|
+
"listr2": "^8.2.1",
|
|
37
38
|
"lodash.snakecase": "^4.1.1",
|
|
38
|
-
"
|
|
39
|
-
"read-
|
|
40
|
-
"yaml": "^2.
|
|
41
|
-
"@aomex/internal-file-import": "^
|
|
42
|
-
"@aomex/internal-tools": "^
|
|
39
|
+
"log-symbols": "^6.0.0",
|
|
40
|
+
"read-package-up": "^11.0.0",
|
|
41
|
+
"yaml": "^2.4.5",
|
|
42
|
+
"@aomex/internal-file-import": "^1.0.3",
|
|
43
|
+
"@aomex/internal-tools": "^1.0.3"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"@aomex/
|
|
48
|
-
"@aomex/
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
46
|
+
"@types/lodash.snakecase": "^4.1.9",
|
|
47
|
+
"stat-mode": "^1.0.0",
|
|
48
|
+
"@aomex/console": "^1.0.3",
|
|
49
|
+
"@aomex/core": "^1.0.3",
|
|
50
|
+
"@aomex/router": "^1.0.3",
|
|
51
|
+
"@aomex/web": "^1.0.3"
|
|
51
52
|
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"test": "vitest"
|
|
54
|
-
}
|
|
53
|
+
"scripts": {}
|
|
55
54
|
}
|