wormajs 0.0.1
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/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/bin/actions.js +245 -0
- package/dist/bin/cli.js +27 -0
- package/dist/bin/progressRenderer.js +47 -0
- package/dist/bin/renderer.js +551 -0
- package/dist/bin/theme.js +26 -0
- package/dist/config.js +19 -0
- package/dist/constant.js +162 -0
- package/dist/core/WorkerPool.js +102 -0
- package/dist/core/loader/astLoader/generates/array.js +34 -0
- package/dist/core/loader/astLoader/generates/enum.js +61 -0
- package/dist/core/loader/astLoader/generates/group.js +41 -0
- package/dist/core/loader/astLoader/generates/index.js +71 -0
- package/dist/core/loader/astLoader/generates/interface.js +59 -0
- package/dist/core/loader/astLoader/generates/simple.js +67 -0
- package/dist/core/loader/astLoader/generates/tuple.js +54 -0
- package/dist/core/loader/astLoader/generates/type.js +2 -0
- package/dist/core/loader/astLoader/generates/utils.js +86 -0
- package/dist/core/loader/astLoader/helper.js +21 -0
- package/dist/core/loader/astLoader/index.js +24 -0
- package/dist/core/loader/astLoader/normalize/index.js +70 -0
- package/dist/core/loader/astLoader/normalize/normalizer.js +69 -0
- package/dist/core/loader/astLoader/normalize/rules/convertTypeArray.js +68 -0
- package/dist/core/loader/astLoader/normalize/rules/handleEmptyType.js +8 -0
- package/dist/core/loader/astLoader/normalize/rules/inferType.js +43 -0
- package/dist/core/loader/astLoader/normalize/rules/mergeAnyOf.js +45 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeCombiningKeywords.js +26 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeEnum.js +38 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeNullType.js +24 -0
- package/dist/core/loader/astLoader/normalize/rules/removeRedundantKeywords.js +27 -0
- package/dist/core/loader/astLoader/normalize/rules/simplifySingleType.js +8 -0
- package/dist/core/loader/astLoader/normalize/rules/validateSchema.js +14 -0
- package/dist/core/loader/astLoader/parsers/array.js +28 -0
- package/dist/core/loader/astLoader/parsers/enum.js +49 -0
- package/dist/core/loader/astLoader/parsers/forward/array.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/enum.js +10 -0
- package/dist/core/loader/astLoader/parsers/forward/group.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/index.js +20 -0
- package/dist/core/loader/astLoader/parsers/forward/object.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/tuple.js +11 -0
- package/dist/core/loader/astLoader/parsers/forward/type.js +2 -0
- package/dist/core/loader/astLoader/parsers/group.js +50 -0
- package/dist/core/loader/astLoader/parsers/index.js +66 -0
- package/dist/core/loader/astLoader/parsers/object.js +44 -0
- package/dist/core/loader/astLoader/parsers/reference.js +41 -0
- package/dist/core/loader/astLoader/parsers/simple.js +48 -0
- package/dist/core/loader/astLoader/parsers/tuple.js +36 -0
- package/dist/core/loader/astLoader/parsers/type.js +2 -0
- package/dist/core/loader/astLoader/parsers/utils.js +58 -0
- package/dist/core/loader/callingCodeLoader/helper.js +183 -0
- package/dist/core/loader/callingCodeLoader/index.js +40 -0
- package/dist/core/loader/index.js +20 -0
- package/dist/core/loader/schemaLoader/index.js +101 -0
- package/dist/core/loader/standardLoader/helper.js +142 -0
- package/dist/core/loader/standardLoader/index.js +38 -0
- package/dist/core/loader/standardLoader/standards.js +105 -0
- package/dist/core/parser/index.js +18 -0
- package/dist/core/parser/openApiParser/helper.js +165 -0
- package/dist/core/parser/openApiParser/index.js +14 -0
- package/dist/core/parser/templateParser/helper.js +333 -0
- package/dist/core/parser/templateParser/index.js +314 -0
- package/dist/core/workerPool/index.js +6 -0
- package/dist/core/workerPool/poolManager.js +45 -0
- package/dist/core/workerPool/swagger2Worker.js +24 -0
- package/dist/core/workerPool/worker.js +61 -0
- package/dist/createConfig.js +37 -0
- package/dist/defineConfig.js +6 -0
- package/dist/functions/getAutoTemplateType.js +37 -0
- package/dist/functions/getFrameworkTag.js +18 -0
- package/dist/functions/prepareConfig.js +41 -0
- package/dist/functions/readWormaRc.js +155 -0
- package/dist/functions/wormaJson.js +232 -0
- package/dist/generate.js +84 -0
- package/dist/helper/PluginDriver.js +98 -0
- package/dist/helper/comment.js +88 -0
- package/dist/helper/config/ConfigHelper.js +79 -0
- package/dist/helper/config/ConfigManager.js +88 -0
- package/dist/helper/config/GeneratorHelper.js +343 -0
- package/dist/helper/config/index.js +19 -0
- package/dist/helper/config/type.js +2 -0
- package/dist/helper/config/zType.js +170 -0
- package/dist/helper/document/index.js +160 -0
- package/dist/helper/index.js +23 -0
- package/dist/helper/logger/index.js +76 -0
- package/dist/helper/progress.js +66 -0
- package/dist/helper/template/index.js +475 -0
- package/dist/index.js +33 -0
- package/dist/plugins/createPlugin.js +30 -0
- package/dist/plugins/index.js +34 -0
- package/dist/plugins/presets/aiDoc.js +173 -0
- package/dist/plugins/presets/apifox.js +56 -0
- package/dist/plugins/presets/filterApi.js +129 -0
- package/dist/plugins/presets/importType.js +49 -0
- package/dist/plugins/presets/payloadModifier/hepler.js +195 -0
- package/dist/plugins/presets/payloadModifier/index.js +122 -0
- package/dist/plugins/presets/payloadModifier/type.js +2 -0
- package/dist/plugins/presets/platform.js +73 -0
- package/dist/plugins/presets/rename.js +209 -0
- package/dist/plugins/presets/tagModifier.js +104 -0
- package/dist/plugins/presets/utils.js +36 -0
- package/dist/readConfig.js +92 -0
- package/dist/resolveWorkspaces.js +83 -0
- package/dist/template/index.js +180 -0
- package/dist/template/presets/ai-doc/SKILL.md.handlebars +29 -0
- package/dist/template/presets/ai-doc/references/{tag}/{api}.md.handlebars +54 -0
- package/dist/template/presets/alova/common/#index.cjs.handlebars +12 -0
- package/dist/template/presets/alova/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/alova/common/helper.cjs.handlebars +13 -0
- package/dist/template/presets/alova/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/alova/common/services/{tag}.cjs.handlebars +28 -0
- package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +15 -0
- package/dist/template/presets/alova/common/typed.d.cts.handlebars +1 -0
- package/dist/template/presets/alova/module/#index.js.handlebars +12 -0
- package/dist/template/presets/alova/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/module/helper.js.handlebars +11 -0
- package/dist/template/presets/alova/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +15 -0
- package/dist/template/presets/alova/module/services/{tag}.js.handlebars +21 -0
- package/dist/template/presets/alova/module/typed.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/alova/partials/build-payload-body.handlebars +22 -0
- package/dist/template/presets/alova/partials/comment.handlebars +19 -0
- package/dist/template/presets/alova/partials/components-body.handlebars +4 -0
- package/dist/template/presets/alova/partials/dts-extra-config.handlebars +8 -0
- package/dist/template/presets/alova/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/alova/partials/extract-responded.handlebars +11 -0
- package/dist/template/presets/alova/partials/stateshook-import.handlebars +9 -0
- package/dist/template/presets/alova/partials/stateshook-option.handlebars +9 -0
- package/dist/template/presets/alova/partials/typed-body.handlebars +43 -0
- package/dist/template/presets/alova/typescript/#index.ts.handlebars +14 -0
- package/dist/template/presets/alova/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/typescript/helper.ts.handlebars +9 -0
- package/dist/template/presets/alova/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +35 -0
- package/dist/template/presets/alova/typescript/typed.ts.handlebars +1 -0
- package/dist/template/presets/alova-globals/common/#index.cjs.handlebars +41 -0
- package/dist/template/presets/alova-globals/common/apiDefinitions.cjs.handlebars +12 -0
- package/dist/template/presets/alova-globals/common/createApis.cjs.handlebars +48 -0
- package/dist/template/presets/alova-globals/common/globals.d.cts.handlebars +2 -0
- package/dist/template/presets/alova-globals/module/#index.js.handlebars +2 -0
- package/dist/template/presets/alova-globals/module/apiDefinitions.js.handlebars +12 -0
- package/dist/template/presets/alova-globals/module/createApis.js.handlebars +44 -0
- package/dist/template/presets/alova-globals/module/globals.d.ts.handlebars +2 -0
- package/dist/template/presets/alova-globals/partials/comment.handlebars +19 -0
- package/dist/template/presets/alova-globals/partials/createApis-proxy-js.handlebars +55 -0
- package/dist/template/presets/alova-globals/partials/globals-d-ts.handlebars +148 -0
- package/dist/template/presets/alova-globals/partials/index-esm.handlebars +38 -0
- package/dist/template/presets/alova-globals/partials/withConfigType-jsdoc.handlebars +22 -0
- package/dist/template/presets/alova-globals/typescript/#index.ts.handlebars +2 -0
- package/dist/template/presets/alova-globals/typescript/apiDefinitions.ts.handlebars +12 -0
- package/dist/template/presets/alova-globals/typescript/createApis.ts.handlebars +99 -0
- package/dist/template/presets/alova-globals/typescript/globals.d.ts.handlebars +2 -0
- package/dist/template/presets/axios/common/#index.cjs.handlebars +22 -0
- package/dist/template/presets/axios/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/axios/common/helper.cjs.handlebars +27 -0
- package/dist/template/presets/axios/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/axios/common/services/{tag}.cjs.handlebars +28 -0
- package/dist/template/presets/axios/common/services/{tag}.d.cts.handlebars +11 -0
- package/dist/template/presets/axios/module/#index.js.handlebars +20 -0
- package/dist/template/presets/axios/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/axios/module/helper.js.handlebars +25 -0
- package/dist/template/presets/axios/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/axios/module/services/{tag}.d.ts.handlebars +11 -0
- package/dist/template/presets/axios/module/services/{tag}.js.handlebars +20 -0
- package/dist/template/presets/axios/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/axios/partials/comment.handlebars +19 -0
- package/dist/template/presets/axios/partials/components-body.handlebars +4 -0
- package/dist/template/presets/axios/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/axios/partials/dts-types.handlebars +7 -0
- package/dist/template/presets/axios/typescript/#index.ts.handlebars +20 -0
- package/dist/template/presets/axios/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/axios/typescript/helper.ts.handlebars +28 -0
- package/dist/template/presets/axios/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +31 -0
- package/dist/template/presets/config/common/worma.config.js.handlebars +9 -0
- package/dist/template/presets/config/module/worma.config.js.handlebars +9 -0
- package/dist/template/presets/config/partials/generator-content.handlebars +45 -0
- package/dist/template/presets/config/typescript/worma.config.ts.handlebars +9 -0
- package/dist/template/presets/fetch/common/#index.cjs.handlebars +17 -0
- package/dist/template/presets/fetch/common/FetchClient.cjs.handlebars +48 -0
- package/dist/template/presets/fetch/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/fetch/common/helper.cjs.handlebars +27 -0
- package/dist/template/presets/fetch/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/fetch/common/services/{tag}.cjs.handlebars +23 -0
- package/dist/template/presets/fetch/common/services/{tag}.d.cts.handlebars +10 -0
- package/dist/template/presets/fetch/module/#index.js.handlebars +15 -0
- package/dist/template/presets/fetch/module/FetchClient.js.handlebars +46 -0
- package/dist/template/presets/fetch/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/fetch/module/helper.js.handlebars +25 -0
- package/dist/template/presets/fetch/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/fetch/module/services/{tag}.d.ts.handlebars +10 -0
- package/dist/template/presets/fetch/module/services/{tag}.js.handlebars +15 -0
- package/dist/template/presets/fetch/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/fetch/partials/comment.handlebars +19 -0
- package/dist/template/presets/fetch/partials/components-body.handlebars +4 -0
- package/dist/template/presets/fetch/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/fetch/partials/dts-types.handlebars +7 -0
- package/dist/template/presets/fetch/typescript/#index.ts.handlebars +15 -0
- package/dist/template/presets/fetch/typescript/FetchClient.ts.handlebars +59 -0
- package/dist/template/presets/fetch/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/fetch/typescript/helper.ts.handlebars +28 -0
- package/dist/template/presets/fetch/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +25 -0
- package/dist/template/presets/ky/module/#index.js.handlebars +14 -0
- package/dist/template/presets/ky/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/ky/module/helper.js.handlebars +27 -0
- package/dist/template/presets/ky/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/ky/module/services/{tag}.d.ts.handlebars +11 -0
- package/dist/template/presets/ky/module/services/{tag}.js.handlebars +19 -0
- package/dist/template/presets/ky/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/ky/partials/comment.handlebars +19 -0
- package/dist/template/presets/ky/partials/components-body.handlebars +4 -0
- package/dist/template/presets/ky/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/ky/partials/dts-types.handlebars +9 -0
- package/dist/template/presets/ky/typescript/#index.ts.handlebars +14 -0
- package/dist/template/presets/ky/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/ky/typescript/helper.ts.handlebars +30 -0
- package/dist/template/presets/ky/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +30 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/type/api.js +14 -0
- package/dist/type/ast.js +24 -0
- package/dist/type/base.js +17 -0
- package/dist/type/index.js +20 -0
- package/dist/type/lib.js +17 -0
- package/dist/type/openapi.js +2 -0
- package/dist/utils/base.js +212 -0
- package/dist/utils/format.js +64 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/openapi.js +417 -0
- package/dist/utils/readPackageJson.js +35 -0
- package/dist/utils/template.js +93 -0
- package/package.json +88 -0
- package/typings/index.d.ts +512 -0
- package/typings/plugins.d.ts +727 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./astLoader"), exports);
|
|
18
|
+
__exportStar(require("./callingCodeLoader"), exports);
|
|
19
|
+
__exportStar(require("./schemaLoader"), exports);
|
|
20
|
+
__exportStar(require("./standardLoader"), exports);
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.schemaLoader = exports.SchemaLoader = void 0;
|
|
7
|
+
const astLoader_1 = require("../astLoader");
|
|
8
|
+
const generates_1 = require("../astLoader/generates");
|
|
9
|
+
const normalize_1 = __importDefault(require("../astLoader/normalize"));
|
|
10
|
+
const parsers_1 = require("../astLoader/parsers");
|
|
11
|
+
/**
|
|
12
|
+
* P0: WeakMap cache for normalized schema.
|
|
13
|
+
* The normalizer clones + transforms the schema (expensive), but the result
|
|
14
|
+
* is independent of commentType/onReference. Caching by schema identity avoids
|
|
15
|
+
* repeated normalization of shared schemas across APIs.
|
|
16
|
+
*/
|
|
17
|
+
const normalizeCache = new WeakMap();
|
|
18
|
+
class SchemaLoader {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.name = 'schemaLoader';
|
|
21
|
+
}
|
|
22
|
+
/** Normalize schema once, with WeakMap caching for repeated identical objects. */
|
|
23
|
+
normalizeSchema(schemaOrigin) {
|
|
24
|
+
const key = schemaOrigin;
|
|
25
|
+
if (normalizeCache.has(key)) {
|
|
26
|
+
return normalizeCache.get(key);
|
|
27
|
+
}
|
|
28
|
+
const normalized = normalize_1.default.normalize(schemaOrigin);
|
|
29
|
+
normalizeCache.set(key, normalized);
|
|
30
|
+
return normalized;
|
|
31
|
+
}
|
|
32
|
+
/** Parse schema to AST: normalize + parse. Uses normalization cache internally. */
|
|
33
|
+
parseSchema(schemaOrigin, parserOptions) {
|
|
34
|
+
const normalized = this.normalizeSchema(schemaOrigin);
|
|
35
|
+
return (0, parsers_1.astParse)(normalized, parserOptions);
|
|
36
|
+
}
|
|
37
|
+
async transform(schemaOrigin, typeOptionsOrOptions, commentOptions) {
|
|
38
|
+
// Dual-output path: third argument present
|
|
39
|
+
if (commentOptions !== undefined) {
|
|
40
|
+
const typeOptions = typeOptionsOrOptions;
|
|
41
|
+
// Normalize once to save the clone+transform cost
|
|
42
|
+
const normalized = this.normalizeSchema(schemaOrigin);
|
|
43
|
+
// Parse for type: respects typeOptions.commentType (default 'doc' for marker transforms)
|
|
44
|
+
const typeAst = (0, parsers_1.astParse)(normalized, {
|
|
45
|
+
document: typeOptions.document,
|
|
46
|
+
commentType: typeOptions.commentType ?? 'doc',
|
|
47
|
+
defaultRequire: typeOptions.defaultRequire,
|
|
48
|
+
refNameMap: typeOptions.refNameMap,
|
|
49
|
+
onReference(ast) {
|
|
50
|
+
typeOptions.onReference?.(ast);
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
// Generate type output
|
|
54
|
+
const typeOutput = await this.generateCode(typeAst, typeOptions);
|
|
55
|
+
// Parse for comment: 'line' preserves raw markers, no onReference needed
|
|
56
|
+
let commentOutput;
|
|
57
|
+
if (commentOptions) {
|
|
58
|
+
const commentAst = (0, parsers_1.astParse)(normalized, {
|
|
59
|
+
document: typeOptions.document,
|
|
60
|
+
commentType: 'line',
|
|
61
|
+
defaultRequire: typeOptions.defaultRequire,
|
|
62
|
+
});
|
|
63
|
+
commentOutput = await this.generateCode(commentAst, commentOptions);
|
|
64
|
+
}
|
|
65
|
+
return { type: typeOutput, comment: commentOutput };
|
|
66
|
+
}
|
|
67
|
+
// Single-output path: original behavior
|
|
68
|
+
const options = typeOptionsOrOptions;
|
|
69
|
+
const ast = this.parseSchema(schemaOrigin, {
|
|
70
|
+
document: options.document,
|
|
71
|
+
commentType: options.commentType ?? 'line',
|
|
72
|
+
defaultRequire: options.defaultRequire,
|
|
73
|
+
refNameMap: options.refNameMap,
|
|
74
|
+
onReference(ast) {
|
|
75
|
+
options.onReference?.(ast);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return this.generateCode(ast, options);
|
|
79
|
+
}
|
|
80
|
+
/** Generate TS code string from an AST node + options. */
|
|
81
|
+
async generateCode(ast, options) {
|
|
82
|
+
const genOptions = {
|
|
83
|
+
deep: options.deep,
|
|
84
|
+
shallowDeep: options.shallowDeep,
|
|
85
|
+
commentType: options.commentType ?? 'line',
|
|
86
|
+
noEnum: options.noEnum,
|
|
87
|
+
};
|
|
88
|
+
const result = await astLoader_1.astLoader.transform(ast, {
|
|
89
|
+
...genOptions,
|
|
90
|
+
format: true,
|
|
91
|
+
});
|
|
92
|
+
const tsStrArr = (0, generates_1.getValue)(result, {
|
|
93
|
+
...genOptions,
|
|
94
|
+
})
|
|
95
|
+
.trim()
|
|
96
|
+
.split('\n');
|
|
97
|
+
return tsStrArr.map((line, idx) => (idx ? options.preText : '') + line).join('\n');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.SchemaLoader = SchemaLoader;
|
|
101
|
+
exports.schemaLoader = new SchemaLoader();
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeIdentifier = makeIdentifier;
|
|
4
|
+
exports.isValidJSIdentifier = isValidJSIdentifier;
|
|
5
|
+
const reservedWords = new Set([
|
|
6
|
+
'abstract',
|
|
7
|
+
'arguments',
|
|
8
|
+
'await',
|
|
9
|
+
'boolean',
|
|
10
|
+
'break',
|
|
11
|
+
'byte',
|
|
12
|
+
'case',
|
|
13
|
+
'catch',
|
|
14
|
+
'char',
|
|
15
|
+
'class',
|
|
16
|
+
'const',
|
|
17
|
+
'continue',
|
|
18
|
+
'debugger',
|
|
19
|
+
'default',
|
|
20
|
+
'delete',
|
|
21
|
+
'do',
|
|
22
|
+
'double',
|
|
23
|
+
'else',
|
|
24
|
+
'enum',
|
|
25
|
+
'eval',
|
|
26
|
+
'export',
|
|
27
|
+
'extends',
|
|
28
|
+
'false',
|
|
29
|
+
'final',
|
|
30
|
+
'finally',
|
|
31
|
+
'float',
|
|
32
|
+
'for',
|
|
33
|
+
'function',
|
|
34
|
+
'goto',
|
|
35
|
+
'if',
|
|
36
|
+
'implements',
|
|
37
|
+
'import',
|
|
38
|
+
'in',
|
|
39
|
+
'instanceof',
|
|
40
|
+
'int',
|
|
41
|
+
'interface',
|
|
42
|
+
'let',
|
|
43
|
+
'long',
|
|
44
|
+
'native',
|
|
45
|
+
'new',
|
|
46
|
+
'null',
|
|
47
|
+
'package',
|
|
48
|
+
'private',
|
|
49
|
+
'protected',
|
|
50
|
+
'public',
|
|
51
|
+
'return',
|
|
52
|
+
'static',
|
|
53
|
+
'super',
|
|
54
|
+
'switch',
|
|
55
|
+
'synchronized',
|
|
56
|
+
'this',
|
|
57
|
+
'throw',
|
|
58
|
+
'throws',
|
|
59
|
+
'transient',
|
|
60
|
+
'true',
|
|
61
|
+
'try',
|
|
62
|
+
'typeof',
|
|
63
|
+
'var',
|
|
64
|
+
'void',
|
|
65
|
+
'volatile',
|
|
66
|
+
'while',
|
|
67
|
+
'with',
|
|
68
|
+
'yield',
|
|
69
|
+
]);
|
|
70
|
+
function splitIntoWords(str) {
|
|
71
|
+
const words = [];
|
|
72
|
+
const UPPERCASE_REGEX = /^[A-Z]$/;
|
|
73
|
+
const LOWERCASE_OR_DIGIT_REGEX = /^[a-z\d]$/;
|
|
74
|
+
const LETTER_REGEX = /[a-z]/i;
|
|
75
|
+
const DIGIT_REGEX = /^\d$/;
|
|
76
|
+
let currentWord = '';
|
|
77
|
+
for (let i = 0; i < str.length; i++) {
|
|
78
|
+
const char = str[i];
|
|
79
|
+
const lastChar = str[i - 1] ?? '';
|
|
80
|
+
const nextChar = str[i + 1] ?? '';
|
|
81
|
+
// 如果遇到非单词字符,结束当前单词
|
|
82
|
+
if (/[^\w$]/.test(char) || ['_'].includes(char)) {
|
|
83
|
+
if (currentWord) {
|
|
84
|
+
words.push(currentWord);
|
|
85
|
+
}
|
|
86
|
+
currentWord = '';
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const isStartOfCamelCase = !UPPERCASE_REGEX.test(lastChar) && UPPERCASE_REGEX.test(char);
|
|
90
|
+
const isUppercaseFollowedByLowercase = UPPERCASE_REGEX.test(char) && LOWERCASE_OR_DIGIT_REGEX.test(nextChar);
|
|
91
|
+
const isTransitionFromDigitToNonDigit = LETTER_REGEX.test(currentWord) && DIGIT_REGEX.test(lastChar) && !DIGIT_REGEX.test(char);
|
|
92
|
+
if (isStartOfCamelCase || isUppercaseFollowedByLowercase || isTransitionFromDigitToNonDigit) {
|
|
93
|
+
if (currentWord) {
|
|
94
|
+
words.push(currentWord);
|
|
95
|
+
}
|
|
96
|
+
currentWord = char;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
currentWord += char;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (currentWord) {
|
|
103
|
+
words.push(currentWord);
|
|
104
|
+
}
|
|
105
|
+
return words;
|
|
106
|
+
}
|
|
107
|
+
function makeIdentifier(str, style) {
|
|
108
|
+
// Removes all characters that are not letters, numbers, underscores, and dollar signs while splitting words
|
|
109
|
+
const words = splitIntoWords(str).filter(Boolean);
|
|
110
|
+
// Convert words to camelCase form
|
|
111
|
+
let identifier = '';
|
|
112
|
+
switch (style) {
|
|
113
|
+
case 'camelCase':
|
|
114
|
+
identifier = words
|
|
115
|
+
.map((word, index) => {
|
|
116
|
+
if (index === 0) {
|
|
117
|
+
return word.toLowerCase();
|
|
118
|
+
}
|
|
119
|
+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
120
|
+
})
|
|
121
|
+
.join('');
|
|
122
|
+
break;
|
|
123
|
+
case 'snakeCase':
|
|
124
|
+
identifier = words.join('_').toLowerCase();
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
identifier = words.join('');
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
// If the string starts with a number, replace it with an underscore
|
|
131
|
+
if (/^\d/.test(identifier)) {
|
|
132
|
+
identifier = `_${identifier}`;
|
|
133
|
+
}
|
|
134
|
+
// If it is a reserved word, add a suffix
|
|
135
|
+
if (reservedWords.has(identifier)) {
|
|
136
|
+
identifier += '_';
|
|
137
|
+
}
|
|
138
|
+
return identifier;
|
|
139
|
+
}
|
|
140
|
+
function isValidJSIdentifier(str) {
|
|
141
|
+
return !!str && /^[a-z_$][\w$]*$/i.test(str) && !reservedWords.has(str);
|
|
142
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.standardLoader = exports.StandardLoader = void 0;
|
|
4
|
+
const helper_1 = require("./helper");
|
|
5
|
+
const standards_1 = require("./standards");
|
|
6
|
+
class StandardLoader {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.name = 'standardLoader';
|
|
9
|
+
}
|
|
10
|
+
transform(input, options) {
|
|
11
|
+
return (0, helper_1.makeIdentifier)(input, options?.style ?? 'camelCase');
|
|
12
|
+
}
|
|
13
|
+
validate(input) {
|
|
14
|
+
return (0, helper_1.isValidJSIdentifier)(input);
|
|
15
|
+
}
|
|
16
|
+
transformRefName(refPath, options) {
|
|
17
|
+
return (0, standards_1.getStandardRefName)(refPath, {
|
|
18
|
+
...options,
|
|
19
|
+
standardLoader: this,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
transformTags(tags) {
|
|
23
|
+
return (0, standards_1.getStandardTags)(tags, {
|
|
24
|
+
standardLoader: this,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
transformOperationId(pathObject, options) {
|
|
28
|
+
return (0, standards_1.getStandardOperationId)(pathObject, {
|
|
29
|
+
...options,
|
|
30
|
+
standardLoader: this,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
transformRadomVariable(value) {
|
|
34
|
+
return (0, standards_1.getRandomVariable)(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.StandardLoader = StandardLoader;
|
|
38
|
+
exports.standardLoader = new StandardLoader();
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStandardOperationId = getStandardOperationId;
|
|
4
|
+
exports.getStandardTags = getStandardTags;
|
|
5
|
+
exports.getRandomVariable = getRandomVariable;
|
|
6
|
+
exports.getStandardRefName = getStandardRefName;
|
|
7
|
+
const utils_1 = require("../../../utils");
|
|
8
|
+
function getStandardOperationId(pathObject, options) {
|
|
9
|
+
const { url, method, map, standardLoader } = options;
|
|
10
|
+
if (standardLoader.validate(pathObject.operationId)) {
|
|
11
|
+
return pathObject.operationId;
|
|
12
|
+
}
|
|
13
|
+
let operationId = '';
|
|
14
|
+
if (pathObject.operationId) {
|
|
15
|
+
operationId = standardLoader.transform(pathObject.operationId, {
|
|
16
|
+
style: 'camelCase',
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
if (!operationId) {
|
|
20
|
+
operationId = standardLoader.transform(`${method}/${url}`, {
|
|
21
|
+
style: 'snakeCase',
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (map.has(operationId)) {
|
|
25
|
+
let num = 1;
|
|
26
|
+
while (map.has(`${operationId}${num}`)) {
|
|
27
|
+
num += 1;
|
|
28
|
+
}
|
|
29
|
+
operationId = `${operationId}${num}`;
|
|
30
|
+
}
|
|
31
|
+
map.add(operationId);
|
|
32
|
+
return operationId;
|
|
33
|
+
}
|
|
34
|
+
function getStandardTags(tags, options) {
|
|
35
|
+
const { standardLoader } = options;
|
|
36
|
+
const tagsSet = new Set();
|
|
37
|
+
if (!tags || !tags.length) {
|
|
38
|
+
return ['general'];
|
|
39
|
+
}
|
|
40
|
+
return tags.map((tag) => {
|
|
41
|
+
tag = tag.trim();
|
|
42
|
+
if (standardLoader.validate(tag)) {
|
|
43
|
+
tagsSet.add(tag);
|
|
44
|
+
return tag;
|
|
45
|
+
}
|
|
46
|
+
let newTag = '';
|
|
47
|
+
if (tag) {
|
|
48
|
+
newTag = standardLoader.transform(tag, {
|
|
49
|
+
style: 'camelCase',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (tagsSet.has(newTag)) {
|
|
53
|
+
let num = 1;
|
|
54
|
+
while (tagsSet.has(`${newTag}${num}`)) {
|
|
55
|
+
num += 1;
|
|
56
|
+
}
|
|
57
|
+
newTag = `${newTag}${num}`;
|
|
58
|
+
}
|
|
59
|
+
if (!newTag) {
|
|
60
|
+
newTag = 'general';
|
|
61
|
+
}
|
|
62
|
+
tagsSet.add(newTag);
|
|
63
|
+
return newTag;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function getRandomVariable(value) {
|
|
67
|
+
return `${(0, utils_1.strHashCode)(value)}`
|
|
68
|
+
.split('')
|
|
69
|
+
.map((code) => {
|
|
70
|
+
let numberCode = Number(code);
|
|
71
|
+
numberCode = Number.isNaN(numberCode) ? 10 : numberCode;
|
|
72
|
+
return String.fromCharCode(numberCode + 97);
|
|
73
|
+
})
|
|
74
|
+
.join('');
|
|
75
|
+
}
|
|
76
|
+
const refPathMap = new Map();
|
|
77
|
+
const refNameSet = new Set();
|
|
78
|
+
function getStandardRefName(refPath, options) {
|
|
79
|
+
const { toUpperCase = true, standardLoader } = options;
|
|
80
|
+
if (refPathMap.has(refPath)) {
|
|
81
|
+
return refPathMap.get(refPath) ?? '';
|
|
82
|
+
}
|
|
83
|
+
const refName = (0, utils_1.get$refName)(refPath, toUpperCase);
|
|
84
|
+
if (standardLoader.validate(refName)) {
|
|
85
|
+
refNameSet.add(refName);
|
|
86
|
+
refPathMap.set(refPath, refName);
|
|
87
|
+
return refName;
|
|
88
|
+
}
|
|
89
|
+
let newRefName = standardLoader.transform(refName, {
|
|
90
|
+
style: 'snakeCase',
|
|
91
|
+
}) || getRandomVariable(refName);
|
|
92
|
+
if (toUpperCase) {
|
|
93
|
+
newRefName = (0, utils_1.capitalizeFirstLetter)(newRefName);
|
|
94
|
+
}
|
|
95
|
+
if (refNameSet.has(newRefName)) {
|
|
96
|
+
let num = 1;
|
|
97
|
+
while (refNameSet.has(`${newRefName}${num}`)) {
|
|
98
|
+
num += 1;
|
|
99
|
+
}
|
|
100
|
+
newRefName = `${newRefName}${num}`;
|
|
101
|
+
}
|
|
102
|
+
refNameSet.add(newRefName);
|
|
103
|
+
refPathMap.set(refPath, newRefName);
|
|
104
|
+
return newRefName;
|
|
105
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./openApiParser"), exports);
|
|
18
|
+
__exportStar(require("./templateParser"), exports);
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getOpenApiDataWithUrl = getOpenApiDataWithUrl;
|
|
7
|
+
exports.getOpenApiData = getOpenApiData;
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
12
|
+
const poolManager_1 = require("../../../core/workerPool/poolManager");
|
|
13
|
+
const helper_1 = require("../../../helper");
|
|
14
|
+
const utils_1 = require("../../../utils");
|
|
15
|
+
const supportedExtname = ['json', 'yaml'];
|
|
16
|
+
function isSwagger2(data) {
|
|
17
|
+
return !!data?.swagger;
|
|
18
|
+
}
|
|
19
|
+
/** 9.3.4: Run CPU-heavy Swagger2→OpenAPI3 conversion via PoolManager */
|
|
20
|
+
function convertSwagger2Async(data) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
// Resolve worker path: .js for production, .ts for vitest/dev
|
|
23
|
+
// In mocked filesystem envs, existsSync may return false — fall back to trying both paths
|
|
24
|
+
const jsPath = node_path_1.default.resolve(__dirname, '../../workerPool/swagger2Worker.js');
|
|
25
|
+
const tsPath = node_path_1.default.resolve(__dirname, '../../workerPool/swagger2Worker.ts');
|
|
26
|
+
const workerScript = (0, node_fs_1.existsSync)(jsPath) ? jsPath : tsPath;
|
|
27
|
+
const pool = poolManager_1.PoolManager.getInstance().get({
|
|
28
|
+
key: 'swagger2Worker',
|
|
29
|
+
workerScript,
|
|
30
|
+
sharedContext: {},
|
|
31
|
+
poolSize: 1,
|
|
32
|
+
});
|
|
33
|
+
pool.processBatch([data]).then((results) => {
|
|
34
|
+
if (results.length > 0 && results[0].openapi) {
|
|
35
|
+
resolve(results[0].openapi);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
reject(new Error('Empty result from swagger2 conversion'));
|
|
39
|
+
}
|
|
40
|
+
}).catch(reject);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Parse local openapi files
|
|
44
|
+
async function parseLocalFile(url, projectPath = process.cwd()) {
|
|
45
|
+
const [, extname] = /\.([^.]+)$/.exec(url) ?? [];
|
|
46
|
+
if (!supportedExtname.includes(extname)) {
|
|
47
|
+
throw helper_1.logger.throwError(`Unsupported file type: ${extname}`, {
|
|
48
|
+
url,
|
|
49
|
+
projectPath,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const filePath = node_path_1.default.resolve(projectPath, url);
|
|
53
|
+
if (extname === 'yaml') {
|
|
54
|
+
return js_yaml_1.default.load(await promises_1.default.readFile(filePath, 'utf-8'));
|
|
55
|
+
}
|
|
56
|
+
// M6-C3: prefer async read, fallback to require() for environments where
|
|
57
|
+
// fs is mocked (e.g. memfs in tests) but the real file exists on disk
|
|
58
|
+
try {
|
|
59
|
+
return JSON.parse(await promises_1.default.readFile(filePath, 'utf-8'));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// Fallback: use require() which bypasses fs mocks to reach real disk
|
|
63
|
+
// eslint-disable-next-line ts/no-require-imports
|
|
64
|
+
return require(filePath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Parse remote openapi files
|
|
68
|
+
async function parseRemoteFile(url, fetchOptions) {
|
|
69
|
+
const dataText = (await (0, utils_1.fetchData)(url, fetchOptions)) ?? '';
|
|
70
|
+
let data;
|
|
71
|
+
try {
|
|
72
|
+
// 尝试解析为 JSON 格式
|
|
73
|
+
data = JSON.parse(dataText);
|
|
74
|
+
}
|
|
75
|
+
catch (jsonError) {
|
|
76
|
+
try {
|
|
77
|
+
// 若 JSON 解析失败,尝试解析为 YAML 格式
|
|
78
|
+
data = js_yaml_1.default.load(dataText);
|
|
79
|
+
}
|
|
80
|
+
catch (yamlError) {
|
|
81
|
+
throw helper_1.logger.throwError(`Only JSON and YAML formats are supported. Parsing failed:
|
|
82
|
+
${jsonError instanceof Error ? jsonError.message : String(jsonError)}
|
|
83
|
+
${yamlError instanceof Error ? yamlError.message : String(yamlError)}`, {
|
|
84
|
+
url,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Validate if the data is valid (prevent server from returning error responses)
|
|
89
|
+
if (!isValidOpenApiData(data)) {
|
|
90
|
+
throw new Error(`Data retrieved from URL ${url} is not a valid OpenAPI document`);
|
|
91
|
+
}
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
// Validate OpenAPI data
|
|
95
|
+
function isValidOpenApiData(data) {
|
|
96
|
+
if (!data || typeof data !== 'object') {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// Check if it's an error response format (e.g., {"code": -1, "msg": "URL does not exist", "data": null})
|
|
100
|
+
if (data.code !== undefined && data.msg !== undefined) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
// Check if it contains required OpenAPI/Swagger structure
|
|
104
|
+
return !!(data.openapi || data.swagger || data.info || data.paths);
|
|
105
|
+
}
|
|
106
|
+
const isRemoteUrl = (u) => /^https?:\/\//.test(u);
|
|
107
|
+
/**
|
|
108
|
+
* Try all URLs in parallel (local & remote) — first successful one wins.
|
|
109
|
+
* Returns the parsed data together with the resolved URL; throws if all URLs fail.
|
|
110
|
+
*/
|
|
111
|
+
async function tryUrls(urls, options) {
|
|
112
|
+
if (urls.length === 0) {
|
|
113
|
+
throw helper_1.logger.throwError('No URLs provided to fetch OpenAPI document');
|
|
114
|
+
}
|
|
115
|
+
const { projectPath, fetchOptions } = options;
|
|
116
|
+
// All URLs race in parallel: local files are fast, remote ones use network
|
|
117
|
+
const tasks = urls.map((u) => {
|
|
118
|
+
if (isRemoteUrl(u)) {
|
|
119
|
+
return parseRemoteFile(u, fetchOptions).then(data => ({ data, url: u }), (err) => {
|
|
120
|
+
throw new Error(`${u}: ${err instanceof Error ? err.message : String(err)}`);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return parseLocalFile(u, projectPath).then(data => ({ data, url: u }));
|
|
124
|
+
});
|
|
125
|
+
try {
|
|
126
|
+
return await Promise.any(tasks);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
const errors = (err instanceof AggregateError)
|
|
130
|
+
? err.errors.map((e) => e.message)
|
|
131
|
+
: [err.message];
|
|
132
|
+
throw helper_1.logger.throwError(`Unable to retrieve valid OpenAPI document from any URL:\n${errors.join('\n')}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Parse OpenAPI document and return the resolved URL alongside the data.
|
|
137
|
+
* Use this when you need to know which URL actually provided the document.
|
|
138
|
+
*/
|
|
139
|
+
async function getOpenApiDataWithUrl(url, options) {
|
|
140
|
+
const { projectPath, fetchOptions } = options ?? {};
|
|
141
|
+
// Normalize to array — single string or array both handled uniformly
|
|
142
|
+
const urls = Array.isArray(url) ? url : [url];
|
|
143
|
+
const { data, url: resolvedUrl } = await tryUrls(urls, { projectPath, fetchOptions });
|
|
144
|
+
let result = data;
|
|
145
|
+
// If it is a swagger2 file — convert via worker to avoid main-thread blocking
|
|
146
|
+
if (isSwagger2(result)) {
|
|
147
|
+
result = await convertSwagger2Async(result);
|
|
148
|
+
}
|
|
149
|
+
if (!result) {
|
|
150
|
+
throw helper_1.logger.throwError(`Cannot read file from ${urls.join(', ')}`, {
|
|
151
|
+
projectPath,
|
|
152
|
+
url,
|
|
153
|
+
fetchOptions,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return { data: result, resolvedUrl };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Parse OpenAPI document from config input.
|
|
160
|
+
* Backward-compatible: wraps {@link getOpenApiDataWithUrl}, returning only the document.
|
|
161
|
+
*/
|
|
162
|
+
async function getOpenApiData(url, options) {
|
|
163
|
+
const { data } = await getOpenApiDataWithUrl(url, options);
|
|
164
|
+
return data;
|
|
165
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openApiParser = exports.OpenApiParser = void 0;
|
|
4
|
+
const helper_1 = require("./helper");
|
|
5
|
+
class OpenApiParser {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.name = 'openapiParser';
|
|
8
|
+
}
|
|
9
|
+
async parse(input, options) {
|
|
10
|
+
return (0, helper_1.getOpenApiData)(input, options);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.OpenApiParser = OpenApiParser;
|
|
14
|
+
exports.openApiParser = new OpenApiParser();
|