@aomex/openapi 0.0.37 → 1.0.4
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 +16 -72
- package/LICENSE +1 -1
- package/dist/index.d.ts +68 -42
- package/dist/index.js +330 -369
- package/dist/index.js.map +1 -1
- package/package.json +20 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,89 +1,33 @@
|
|
|
1
1
|
# @aomex/openapi
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.0.4
|
|
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
|
+
- [`15ccdc7`](https://github.com/aomex/aomex/commit/15ccdc73ab61f7852e123dac7c1c5a2878f8accd) Thanks [@geekact](https://github.com/geekact)! - feat(openapi): 文件名增加下划线
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
- [`680b7dc`](https://github.com/aomex/aomex/commit/680b7dce3b4a9b6799dea10f212d1fe98ebe0daa) Thanks [@geekact](https://github.com/geekact)! - fix(openapi)!: 保存文件设置为false没有意义
|
|
14
10
|
|
|
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
|
|
11
|
+
- [`f01a7f5`](https://github.com/aomex/aomex/commit/f01a7f57e6c89e22e8de65cbed7107a4ac23ed27) Thanks [@geekact](https://github.com/geekact)! - refactor(openapi): 使用fs.readFile代替read-package-up包
|
|
40
12
|
|
|
41
|
-
|
|
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
|
|
13
|
+
- [`6c2881f`](https://github.com/aomex/aomex/commit/6c2881f6d3fa62d2cd40d0b3544f3afab0448a7b) Thanks [@geekact](https://github.com/geekact)! - feat(openapi): 保存文件时增加flush属性
|
|
48
14
|
|
|
49
|
-
|
|
15
|
+
- [`a1a1787`](https://github.com/aomex/aomex/commit/a1a1787c791bf113c7e87e4435ea364eb8ce8eb8) Thanks [@geekact](https://github.com/geekact)! - refactor: 使用node内置的 util.styleText 替换 chalk 包
|
|
50
16
|
|
|
51
|
-
|
|
17
|
+
- [`100aec4`](https://github.com/aomex/aomex/commit/100aec48dd843dfd91184b9820e9e33c40aabf58) Thanks [@geekact](https://github.com/geekact)! - feat(router,openapi)!: 删除head路由
|
|
52
18
|
|
|
53
|
-
- [`
|
|
19
|
+
- [`42447fb`](https://github.com/aomex/aomex/commit/42447fb9d3916c4d6242841d1fa3eab67e48be70) Thanks [@geekact](https://github.com/geekact)! - refactor(core): 重命名I18nFormat为I18nMessage
|
|
54
20
|
|
|
55
|
-
- Updated dependencies [[`
|
|
56
|
-
- @aomex/
|
|
57
|
-
- @aomex/
|
|
58
|
-
- @aomex/router@0.0.27
|
|
59
|
-
- @aomex/web@0.0.25
|
|
21
|
+
- Updated dependencies [[`a1a1787`](https://github.com/aomex/aomex/commit/a1a1787c791bf113c7e87e4435ea364eb8ce8eb8)]:
|
|
22
|
+
- @aomex/internal-tools@1.0.4
|
|
23
|
+
- @aomex/internal-file-import@1.0.4
|
|
60
24
|
|
|
61
|
-
##
|
|
25
|
+
## 1.0.3
|
|
62
26
|
|
|
63
27
|
### Patch Changes
|
|
64
28
|
|
|
65
|
-
- [`
|
|
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): 对象使用统一逻辑转换成验证器
|
|
29
|
+
- [`eb8b1eb`](https://github.com/aomex/aomex/commit/eb8b1ebdc7072d7ee9c7ba8e1f324e802753416d) Thanks [@geekact](https://github.com/geekact)! - feat(openapi): 文档生成工具
|
|
84
30
|
|
|
85
|
-
- Updated dependencies [
|
|
86
|
-
- @aomex/
|
|
87
|
-
- @aomex/
|
|
88
|
-
- @aomex/console@0.0.27
|
|
89
|
-
- @aomex/router@0.0.25
|
|
31
|
+
- Updated dependencies []:
|
|
32
|
+
- @aomex/internal-file-import@1.0.3
|
|
33
|
+
- @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, I18nMessage } 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?: 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: I18nMessage;
|
|
43
|
+
search_routers_files: I18nMessage;
|
|
44
|
+
parse_routers: I18nMessage;
|
|
45
|
+
add_tag: I18nMessage;
|
|
46
|
+
hand_fix_documentation: I18nMessage;
|
|
47
|
+
optimize_parameter: I18nMessage;
|
|
48
|
+
save_to_file: I18nMessage;
|
|
49
|
+
validate: I18nMessage;
|
|
50
|
+
help_summary: I18nMessage;
|
|
51
|
+
has_error: I18nMessage<{
|
|
52
|
+
count: number;
|
|
53
|
+
}>;
|
|
54
|
+
has_warning: I18nMessage<{
|
|
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 {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
return ctx.cli.config({
|
|
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
|
-
};
|
|
152
|
-
|
|
153
|
-
// src/lib/remove-duplicate-schema.ts
|
|
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
|
-
};
|
|
4
|
+
// src/lib/generate-document.ts
|
|
5
|
+
import { i18n } from "@aomex/core";
|
|
6
|
+
import { sleep } from "@aomex/internal-tools";
|
|
7
|
+
import { pathToFiles } from "@aomex/internal-file-import";
|
|
8
|
+
import path4 from "node:path";
|
|
187
9
|
|
|
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,368 @@ 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/hoist-parameter.ts
|
|
50
|
+
var methodParameterToPathParameter = (document) => {
|
|
51
|
+
pathLoop: for (const path5 of Object.values(document.paths)) {
|
|
52
|
+
const parametersHandler = {};
|
|
53
|
+
let methodCounter = 0;
|
|
54
|
+
for (const method of methods) {
|
|
55
|
+
const methodItem = path5[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
|
+
path5.parameters ||= [];
|
|
79
|
+
path5.parameters.push(JSON.parse(uniqueKey));
|
|
80
|
+
handlers.forEach((fn) => fn());
|
|
81
|
+
});
|
|
82
|
+
if (path5.parameters && !path5.parameters.length) {
|
|
83
|
+
delete path5.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, flush: true });
|
|
99
|
+
return { dest, size };
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/lib/initialize-document.ts
|
|
103
|
+
import { readFile } from "node:fs/promises";
|
|
104
|
+
import path2 from "node:path";
|
|
105
|
+
var initializeDocument = async (basic) => {
|
|
106
|
+
const document = JSON.parse(JSON.stringify(basic || {}));
|
|
107
|
+
document.openapi ||= "3.0.3";
|
|
108
|
+
document.tags ||= [];
|
|
109
|
+
document.info ||= { title: "", version: "" };
|
|
110
|
+
document.paths = {};
|
|
111
|
+
document.info.title ||= (await readPackageJson()).name || "OpenAPI";
|
|
112
|
+
document.info.version ||= (await readPackageJson()).version || "0.0.0";
|
|
113
|
+
return document;
|
|
114
|
+
};
|
|
115
|
+
var readPackageJson = async () => {
|
|
116
|
+
try {
|
|
117
|
+
const content = await readFile(path2.resolve("package.json"), "utf8");
|
|
118
|
+
const json = JSON.parse(content);
|
|
119
|
+
return json && typeof json === "object" ? json : {};
|
|
120
|
+
} catch {
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/lib/generate-document.ts
|
|
126
|
+
import { Listr } from "listr2";
|
|
127
|
+
|
|
128
|
+
// src/lib/parse-files.ts
|
|
129
|
+
import { flattenMiddlewareToken } from "@aomex/core";
|
|
130
|
+
import { getFileValues } from "@aomex/internal-file-import";
|
|
131
|
+
import { Router } from "@aomex/router";
|
|
132
|
+
import { WebMiddleware } from "@aomex/web";
|
|
133
|
+
import path3 from "node:path";
|
|
134
|
+
|
|
135
|
+
// src/lib/method-to-verb.ts
|
|
136
|
+
var methodToVerb = (method, uri) => {
|
|
137
|
+
method = method.toLowerCase();
|
|
138
|
+
if (method === "get") return uri.includes(":") ? "retrieve" : "list";
|
|
139
|
+
if (method === "post") return "create";
|
|
140
|
+
if (method === "put") return "replace";
|
|
141
|
+
if (method === "patch") return "update";
|
|
142
|
+
return method;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/lib/parse-files.ts
|
|
146
|
+
import snakeCase from "lodash.snakecase";
|
|
147
|
+
var parseFiles = async (document, files) => {
|
|
237
148
|
const usedTags = [];
|
|
149
|
+
const data = [];
|
|
238
150
|
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(
|
|
151
|
+
const routers = await getFileValues(
|
|
247
152
|
[file],
|
|
248
153
|
(item) => !!item && item instanceof Router
|
|
249
154
|
);
|
|
250
155
|
for (const router of routers) {
|
|
251
|
-
const groupMiddlewareList =
|
|
156
|
+
const groupMiddlewareList = flattenMiddlewareToken(router["middlewareChain"]);
|
|
252
157
|
const builders = router["builders"];
|
|
253
158
|
for (const builder of builders) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
responses: {}
|
|
263
|
-
...builder.docs
|
|
159
|
+
const builderMiddlewareList = groupMiddlewareList.concat(builder["middlewareList"]).filter((middleware2) => middleware2 instanceof WebMiddleware);
|
|
160
|
+
for (const uri of builder["uris"]) {
|
|
161
|
+
const pathName = normalizePath(uri);
|
|
162
|
+
const pathItem = document.paths[pathName] ||= {};
|
|
163
|
+
for (const method of builder["methods"]) {
|
|
164
|
+
const methodName = method.toLowerCase();
|
|
165
|
+
const methodItem = pathItem[methodName] = {
|
|
166
|
+
...builder.docs,
|
|
167
|
+
responses: {}
|
|
264
168
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
middleware3.toDocument({
|
|
270
|
-
document,
|
|
169
|
+
data.push(
|
|
170
|
+
...builderMiddlewareList.map((item) => {
|
|
171
|
+
return {
|
|
172
|
+
injector: item["openapi"](),
|
|
271
173
|
pathItem,
|
|
272
|
-
|
|
273
|
-
methodItem
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
methodToVerb(method, uri) + " " + uri.replaceAll(":", "_by_")
|
|
174
|
+
pathName,
|
|
175
|
+
methodItem,
|
|
176
|
+
methodName,
|
|
177
|
+
file,
|
|
178
|
+
uri
|
|
179
|
+
};
|
|
180
|
+
})
|
|
280
181
|
);
|
|
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
182
|
}
|
|
293
183
|
}
|
|
294
184
|
}
|
|
295
185
|
}
|
|
296
186
|
}
|
|
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
|
-
}
|
|
187
|
+
for (const { injector } of data) {
|
|
188
|
+
injector.onDocument?.(document);
|
|
307
189
|
}
|
|
308
|
-
{
|
|
309
|
-
|
|
310
|
-
if (config.fix) {
|
|
311
|
-
config.fix(document);
|
|
312
|
-
} else {
|
|
313
|
-
emitter.emit("replace", skip(msg));
|
|
314
|
-
}
|
|
190
|
+
for (const { injector, pathItem, pathName } of data) {
|
|
191
|
+
injector.onPath?.(pathItem, { document, pathName });
|
|
315
192
|
}
|
|
316
|
-
{
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
193
|
+
for (const { injector, pathItem, pathName, methodItem, methodName } of data) {
|
|
194
|
+
injector.onMethod?.(methodItem, {
|
|
195
|
+
document,
|
|
196
|
+
pathItem,
|
|
197
|
+
pathName,
|
|
198
|
+
methodName
|
|
199
|
+
});
|
|
320
200
|
}
|
|
321
|
-
{
|
|
322
|
-
|
|
323
|
-
|
|
201
|
+
for (const { injector, pathItem, pathName, methodItem, methodName } of data) {
|
|
202
|
+
injector.postMethod?.(methodItem, {
|
|
203
|
+
document,
|
|
204
|
+
pathItem,
|
|
205
|
+
pathName,
|
|
206
|
+
methodName
|
|
207
|
+
});
|
|
324
208
|
}
|
|
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
|
-
}
|
|
209
|
+
for (const { injector, pathItem, pathName } of data) {
|
|
210
|
+
injector.postPath?.(pathItem, { document, pathName });
|
|
346
211
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
emitter.emit("msg", msg = "\u9A8C\u8BC1");
|
|
350
|
-
result = await validate(document);
|
|
212
|
+
for (const { injector } of data) {
|
|
213
|
+
injector.postDocument?.(document);
|
|
351
214
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
215
|
+
for (const { methodItem, methodName, file, uri } of data) {
|
|
216
|
+
methodItem.tags ||= [getTagByFilename(file)];
|
|
217
|
+
methodItem.operationId ||= snakeCase(
|
|
218
|
+
methodToVerb(methodName, uri) + " " + uri.replaceAll(":", "_by_")
|
|
219
|
+
);
|
|
220
|
+
if (methodName === "post") {
|
|
221
|
+
methodItem["x-codegen-request-body-name"] = "body";
|
|
357
222
|
}
|
|
358
|
-
|
|
223
|
+
if (!Object.keys(methodItem.responses).length) {
|
|
224
|
+
methodItem.responses = { default: { description: "" } };
|
|
225
|
+
}
|
|
226
|
+
usedTags.push(...methodItem.tags);
|
|
227
|
+
}
|
|
228
|
+
return [...new Set(usedTags)];
|
|
359
229
|
};
|
|
360
|
-
var skip = (message) => message + " " + chalk2.gray("[\u8DF3\u8FC7]");
|
|
361
230
|
var normalizePath = (uri) => {
|
|
362
231
|
return uri.replace(/:([a-z0-9_?]+)/gi, (_, $1) => {
|
|
363
232
|
return `{${$1.replace(/[?]/g, "")}}`;
|
|
364
233
|
});
|
|
365
234
|
};
|
|
366
235
|
var getTagByFilename = (file) => {
|
|
367
|
-
return
|
|
236
|
+
return path3.basename(file).replace(/\..+$/, "");
|
|
368
237
|
};
|
|
369
238
|
|
|
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
|
-
|
|
414
|
-
|
|
415
|
-
|
|
239
|
+
// src/lib/generate-document.ts
|
|
240
|
+
import logSymbols from "log-symbols";
|
|
241
|
+
|
|
242
|
+
// src/lib/append-tag.ts
|
|
243
|
+
var appendTag = (document, usedTags) => {
|
|
244
|
+
const tags = document.tags ||= [];
|
|
245
|
+
const definedTags = tags.map((item) => item.name);
|
|
246
|
+
const undefinedTags = usedTags.filter((tag) => !definedTags.includes(tag)).sort();
|
|
247
|
+
for (const tag of undefinedTags) {
|
|
248
|
+
tags.push({ name: tag });
|
|
249
|
+
}
|
|
250
|
+
return undefinedTags;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/lib/generate-document.ts
|
|
254
|
+
import { styleText } from "node:util";
|
|
255
|
+
var generateDocument = async (config) => {
|
|
256
|
+
const spinner = new Listr([], { concurrent: false, exitOnError: true });
|
|
257
|
+
spinner.add({
|
|
258
|
+
title: i18n.t("openapi.initialize"),
|
|
259
|
+
task: async (ctx) => {
|
|
260
|
+
ctx.document = await initializeDocument(config.docs);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
spinner.add({
|
|
264
|
+
title: i18n.t("openapi.search_routers_files"),
|
|
265
|
+
task: async (ctx) => {
|
|
266
|
+
ctx.files = await pathToFiles(config.routers);
|
|
267
|
+
await sleep(500);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
spinner.add({
|
|
271
|
+
title: i18n.t("openapi.parse_routers"),
|
|
272
|
+
task: async (ctx) => {
|
|
273
|
+
ctx.usedTags = await parseFiles(ctx.document, ctx.files);
|
|
274
|
+
await sleep(500);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
spinner.add({
|
|
278
|
+
title: i18n.t("openapi.add_tag"),
|
|
279
|
+
task: (ctx, task) => {
|
|
280
|
+
const undefinedTags = appendTag(ctx.document, ctx.usedTags);
|
|
281
|
+
if (undefinedTags.length) {
|
|
282
|
+
task.title += " " + styleText("gray", undefinedTags.join(","));
|
|
283
|
+
} else {
|
|
284
|
+
task.skip();
|
|
416
285
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
spinner.add({
|
|
289
|
+
title: i18n.t("openapi.hand_fix_documentation"),
|
|
290
|
+
skip: !config.fix,
|
|
291
|
+
task: async (ctx) => {
|
|
292
|
+
await config.fix(ctx.document);
|
|
293
|
+
await sleep(500);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
spinner.add({
|
|
297
|
+
title: i18n.t("openapi.optimize_parameter"),
|
|
298
|
+
task: async (ctx) => {
|
|
299
|
+
methodParameterToPathParameter(ctx.document);
|
|
300
|
+
await sleep(500);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
spinner.add({
|
|
304
|
+
title: i18n.t("openapi.save_to_file"),
|
|
305
|
+
task: async (ctx, task) => {
|
|
306
|
+
const result = await saveToFile(ctx.document, config.saveToFile, config.fileMode);
|
|
307
|
+
task.title += " " + styleText(["blue", "underline"], path4.relative(process.cwd(), result.dest)) + styleText("green", ` [${result.size}]`);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
spinner.add({
|
|
311
|
+
title: i18n.t("openapi.validate"),
|
|
312
|
+
task: async (ctx, task) => {
|
|
313
|
+
const result = ctx.validateResult = await validateOpenapi(ctx.document);
|
|
314
|
+
await sleep(500);
|
|
315
|
+
const summary = [];
|
|
316
|
+
if (result.errors.length) {
|
|
317
|
+
summary.push(i18n.t("openapi.has_error", { count: result.errors.length }));
|
|
318
|
+
}
|
|
319
|
+
if (result.warnings.length) {
|
|
320
|
+
summary.push(i18n.t("openapi.has_warning", { count: result.warnings.length }));
|
|
422
321
|
}
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
result.warnings.forEach((item) => {
|
|
426
|
-
spinner.warn(formatValidateMessage(item));
|
|
427
|
-
});
|
|
322
|
+
if (summary.length) {
|
|
323
|
+
task.title += " " + styleText("yellow", summary.join(" & "));
|
|
428
324
|
}
|
|
429
|
-
}
|
|
430
|
-
);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
const context = await spinner.run({});
|
|
328
|
+
const { errors, warnings } = context.validateResult;
|
|
329
|
+
for (const error of errors) {
|
|
330
|
+
console.log(` ${logSymbols.error} ${formatValidateMessage(error)}`);
|
|
331
|
+
}
|
|
332
|
+
for (const warning of warnings) {
|
|
333
|
+
console.log(` ${logSymbols.warning} ${formatValidateMessage(warning)}`);
|
|
334
|
+
}
|
|
335
|
+
return JSON.parse(JSON.stringify(context.document));
|
|
431
336
|
};
|
|
432
337
|
var formatValidateMessage = (item) => {
|
|
433
338
|
let pathname = item.path.length ? item.path.join(".") : "";
|
|
434
|
-
return `[${pathname || "."}] ${item.message}`;
|
|
339
|
+
return `${styleText("gray", `[${pathname || "."}]`)} ${item.message}`;
|
|
435
340
|
};
|
|
341
|
+
|
|
342
|
+
// src/openapi.ts
|
|
343
|
+
var commandName = "openapi";
|
|
344
|
+
var openapi = (options) => {
|
|
345
|
+
return middleware.console({
|
|
346
|
+
fn: async (ctx, next) => {
|
|
347
|
+
if (ctx.input.command !== commandName) return next();
|
|
348
|
+
ctx.commandMatched = true;
|
|
349
|
+
await generateDocument(options);
|
|
350
|
+
},
|
|
351
|
+
help: {
|
|
352
|
+
onDocument(doc) {
|
|
353
|
+
doc[commandName] = { summary: i18n2.t("openapi.help_summary") };
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// src/i18n/locales/zh-cn.ts
|
|
360
|
+
import { i18n as i18n3 } from "@aomex/core";
|
|
361
|
+
i18n3.register("zh_CN", "openapi", {
|
|
362
|
+
initialize: "\u521D\u59CB\u5316\u6587\u6863",
|
|
363
|
+
search_routers_files: "\u641C\u7D22\u8DEF\u7531\u6587\u4EF6",
|
|
364
|
+
parse_routers: "\u89E3\u6790\u8DEF\u7531",
|
|
365
|
+
add_tag: "\u589E\u52A0\u6807\u7B7E",
|
|
366
|
+
hand_fix_documentation: "\u624B\u52A8\u4FEE\u590D\u6587\u6863",
|
|
367
|
+
optimize_parameter: "\u4F18\u5316\u53C2\u6570",
|
|
368
|
+
save_to_file: "\u4FDD\u5B58\u5230\u6587\u4EF6",
|
|
369
|
+
validate: "\u9A8C\u8BC1",
|
|
370
|
+
help_summary: "openapi v3 \u6587\u6863\u751F\u6210\u5668",
|
|
371
|
+
has_error: "\u5171{{count}}\u6761\u62A5\u9519",
|
|
372
|
+
has_warning: "\u5171{{count}}\u6761\u8B66\u544A"
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// src/i18n/locales/en-us.ts
|
|
376
|
+
import { i18n as i18n4 } from "@aomex/core";
|
|
377
|
+
i18n4.register("en_US", "openapi", {
|
|
378
|
+
initialize: "initialize document",
|
|
379
|
+
search_routers_files: "search web routers files",
|
|
380
|
+
parse_routers: "parse routers",
|
|
381
|
+
add_tag: "append tags",
|
|
382
|
+
hand_fix_documentation: "fix documentation by manual",
|
|
383
|
+
optimize_parameter: "optimize parameters",
|
|
384
|
+
save_to_file: "save to file",
|
|
385
|
+
validate: "validate",
|
|
386
|
+
help_summary: "openapi v3 documentation generator",
|
|
387
|
+
has_error: "total {{count}} errors",
|
|
388
|
+
has_warning: "total {{count}} warnings"
|
|
389
|
+
});
|
|
436
390
|
export {
|
|
437
391
|
generateDocument,
|
|
438
|
-
|
|
392
|
+
initializeDocument,
|
|
393
|
+
methodParameterToPathParameter,
|
|
394
|
+
methodToVerb,
|
|
395
|
+
methods,
|
|
396
|
+
openapi,
|
|
397
|
+
parseFiles,
|
|
398
|
+
saveToFile,
|
|
399
|
+
validateOpenapi
|
|
439
400
|
};
|
|
440
401
|
//# 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,IACp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,QAAQ,KAAK,GAAG,OAAO,SAAS,MAAM,oBAAK;AAEzD,YAAI,MAAM,QAAQ;AAClB,gBAAQ,WAAW,OAAO,MAAMC,OAAM,OAAO,QAAQ,KAAK,QAAG,CAAC;AAC9D,YAAI,UAAU;AACZ,kBAAQ,KAAK,GAAG;AAAA,QAClB,WAAW,YAAY;AACrB,kBAAQ,KAAK,GAAG;AAAA,QAClB,OAAO;AACL,kBAAQ,QAAQ;AAAA,QAClB;AAAA,MACF,SAAS,GAAG;AACV,gBAAQ;AAAA,UACN,QAAQ,OAAO,MAAMA,OAAM,IAAI,IAAK,EAAY,OAAO,GAAG;AAAA,QAC5D;AACA;AAAA,MACF;AAEA,UAAI,UAAU;AACZ,gBAAQ,SAAS;AACjB,eAAO,OAAO,QAAQ,CAAC,SAAS;AAC9B,kBAAQ,KAAK,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/hoist-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 { sleep } 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 './hoist-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';\nimport { styleText } from 'node:util';\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?: 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 await sleep(500);\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 await sleep(500);\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 += ' ' + styleText('gray', 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 await sleep(500);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.optimize_parameter'),\n task: async (ctx) => {\n methodParameterToPathParameter(ctx.document);\n await sleep(500);\n },\n });\n\n spinner.add({\n title: i18n.t('openapi.save_to_file'),\n task: async (ctx, task) => {\n const result = await saveToFile(ctx.document, config.saveToFile, config.fileMode);\n task.title +=\n ' ' +\n styleText(['blue', 'underline'], path.relative(process.cwd(), result.dest)) +\n styleText('green', ` [${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 await sleep(500);\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 += ' ' + styleText('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 `${styleText('gray', `[${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, flush: true });\n\n return { dest, size };\n};\n","import type { OpenAPI } from '@aomex/core';\nimport type { OpenapiOptions } from './generate-document';\nimport { readFile } from 'node:fs/promises';\nimport path from 'node:path';\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 readPackageJson()).name || 'OpenAPI';\n document.info.version ||= (await readPackageJson()).version || '0.0.0';\n return document;\n};\n\nconst readPackageJson = async (): Promise<{ name?: string; version?: string }> => {\n try {\n const content = await readFile(path.resolve('package.json'), 'utf8');\n const json = JSON.parse(content);\n return json && typeof json === 'object' ? json : {};\n } catch {\n return {};\n }\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\n for (const method of builder['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;;;ACHjB,OAAO,eAA2C;AAClD,SAAS,WAAW;AAUpB,IAAM,WAAW,IAAI,UAAU,SAAS;AACxC,SAAS,WAAW;AAAA,EAClB,SAAS;AAAA;AAAA,EAET,OAAO;AAAA,IACL,gBAAgB;AAAA,IAChB,oBAAoB;AAAA,EACtB;AACF,CAAC;AAYM,IAAM,kBAAkB,OAAO,aAA+B;AACnE,QAAM,SAAgC;AAAA,IACpC,UAAU,CAAC;AAAA,IACX,QAAQ,CAAC;AAAA,EACX;AACA,QAAM,eAAe,MAAM,SAAS,IAAI,QAA8C;AACtF,eAAa,QAAQ,CAAC,SAAS;AAC7B,WAAO,KAAK,aAAa,gBAA2B,WAAW,UAAU,EAAE,KAAK;AAAA,MAC9E,MAAM,KAAK,KAAK,IAAI,MAAM;AAAA,MAC1B,SAAS,KAAK;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;;;AC7CO,IAAM,UAAiB;AAAA,EAC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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","path","middleware","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.4",
|
|
4
|
+
"description": "Openapi文档生成工具",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -26,30 +26,28 @@
|
|
|
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
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"@aomex/internal-
|
|
42
|
-
"@aomex/internal-tools": "^0.0.27"
|
|
39
|
+
"log-symbols": "^6.0.0",
|
|
40
|
+
"yaml": "^2.4.5",
|
|
41
|
+
"@aomex/internal-file-import": "^1.0.4",
|
|
42
|
+
"@aomex/internal-tools": "^1.0.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"@aomex/
|
|
48
|
-
"@aomex/
|
|
49
|
-
"@
|
|
50
|
-
"
|
|
45
|
+
"@types/lodash.snakecase": "^4.1.9",
|
|
46
|
+
"stat-mode": "^1.0.0",
|
|
47
|
+
"@aomex/console": "^1.0.4",
|
|
48
|
+
"@aomex/core": "^1.0.4",
|
|
49
|
+
"@aomex/router": "^1.0.4",
|
|
50
|
+
"@aomex/web": "^1.0.4"
|
|
51
51
|
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"test": "vitest"
|
|
54
|
-
}
|
|
52
|
+
"scripts": {}
|
|
55
53
|
}
|