@povio/openapi-codegen-cli 3.1.1 → 3.2.0-rc.10
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/README.md +63 -15
- package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +6 -20
- package/dist/acl.mjs +8 -13
- package/dist/{auth.context-Bu5KW2sI.mjs → auth.context-COWO6ssl.mjs} +1 -21
- package/dist/auth.d.mts +2 -0
- package/dist/auth.mjs +3 -0
- package/dist/axios.d.mts +2 -0
- package/dist/axios.mjs +2 -0
- package/dist/{config-BU7wVf7U.d.mts → config-DgrOddSC.d.mts} +1 -2
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-DSI86D3u.mjs → error-handling-BeydPL7s.mjs} +21 -51
- package/dist/{error-handling-D-mHJ60d.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/generate.runner-CD7mlcJ4.mjs +184 -0
- package/dist/generate.utils-CT-LA-gX.cjs +2267 -0
- package/dist/generateCodeFromOpenAPIDoc-D9W5BtAt.mjs +2097 -0
- package/dist/{generateCodeFromOpenAPIDoc-DseBECa-.mjs → generateCodeFromOpenAPIDoc-DhI7CHeh.cjs} +1349 -2344
- package/dist/generator.d.mts +3 -10
- package/dist/generator.mjs +9 -9
- package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +2011 -0
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +12 -200
- package/dist/index.mjs +12 -264
- package/dist/metro.cjs +114 -4959
- package/dist/metro.d.mts +3 -4
- package/dist/metro.mjs +4 -9
- package/dist/native-bindings-BTQGSGhU.mjs +1480 -0
- package/dist/native-rest-interceptor-CAWR8H5Y.mjs +208 -0
- package/dist/native-rest-interceptor-Cz6saoq5.d.mts +46 -0
- package/dist/native.d.mts +3 -0
- package/dist/native.mjs +3 -0
- package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
- package/dist/openapi-codegen-native-linux-x64.node +0 -0
- package/dist/openapi-codegen-native-win32-x64.node +0 -0
- package/dist/{openapi-codegen.runner-Co_bG00_.mjs → openapi-codegen.runner-C4TIXQNx.mjs} +4 -5
- package/dist/{openapi-source.runner-wLs5vqw6.mjs → openapi-source.runner-BZ6ZLgRO.mjs} +19 -10
- package/dist/{openapi-source.runner-BSIrB6ny.d.mts → openapi-source.runner-ykstqlPC.d.mts} +2 -8
- package/dist/{options-CE4Koxof.d.mts → options-KPf-Fti5.d.mts} +6 -1
- package/dist/query.d.mts +3 -0
- package/dist/query.mjs +3 -0
- package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
- package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
- package/dist/rest-client-CQyFvqYC.d.mts +55 -0
- package/dist/rest-interceptor-D5NCNTm1.mjs +115 -0
- package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
- package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
- package/dist/rest.d.mts +2 -0
- package/dist/rest.mjs +2 -0
- package/dist/rest.utils-rezWAIYL.d.mts +10 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +41 -71
- package/dist/tiny.d.mts +1 -3
- package/dist/tiny.mjs +2 -3
- package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.d.mts +3 -4
- package/dist/vite.mjs +6 -10
- package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
- package/dist/workspace.context-isVY9ves.d.mts +23 -0
- package/dist/zod.d.mts +2 -7
- package/dist/zod.mjs +2 -4
- package/package.json +73 -26
- package/dist/generate.runner-C1HrS_9G.mjs +0 -90
package/dist/vite.mjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-Co_bG00_.mjs";
|
|
4
|
-
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-wLs5vqw6.mjs";
|
|
1
|
+
import { t as createOpenApiCodegenRunner } from "./openapi-codegen.runner-C4TIXQNx.mjs";
|
|
2
|
+
import { i as normalizeWatchFolders, r as isTinyOpenApiFakeMode, t as createTinyOpenApiSourceRunner } from "./openapi-source.runner-BZ6ZLgRO.mjs";
|
|
5
3
|
import path from "path";
|
|
6
|
-
|
|
7
4
|
//#region src/vite/openapi-codegen.plugin.ts
|
|
8
5
|
function openApiCodegen(config) {
|
|
9
6
|
let resolvedViteConfig;
|
|
@@ -37,10 +34,9 @@ function openApiCodegen(config) {
|
|
|
37
34
|
}
|
|
38
35
|
};
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
//#endregion
|
|
42
38
|
//#region src/vite/tiny-openapi-codegen.plugin.ts
|
|
43
|
-
const watchedEvents = new Set([
|
|
39
|
+
const watchedEvents = /* @__PURE__ */ new Set([
|
|
44
40
|
"add",
|
|
45
41
|
"change",
|
|
46
42
|
"unlink"
|
|
@@ -79,7 +75,8 @@ function tinyOpenApiCodegenPlugin(codegenConfig, options) {
|
|
|
79
75
|
}, debounceMs);
|
|
80
76
|
};
|
|
81
77
|
const setupWatcher = (server) => {
|
|
82
|
-
const
|
|
78
|
+
const root = resolvedConfig?.root ?? server.config.root;
|
|
79
|
+
const watchFolders = normalizeWatchFolders(root, options.watchFolders);
|
|
83
80
|
server.watcher.add(watchFolders);
|
|
84
81
|
server.watcher.on("all", (event, changedPath) => {
|
|
85
82
|
if (watchedEvents.has(event) && isPathInWatchFolders(changedPath, watchFolders)) scheduleGenerate(server);
|
|
@@ -111,6 +108,5 @@ function isPathInWatchFolders(changedPath, watchFolders) {
|
|
|
111
108
|
return relativePath === "" || !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
|
|
112
109
|
});
|
|
113
110
|
}
|
|
114
|
-
|
|
115
111
|
//#endregion
|
|
116
|
-
export { openApiCodegen, tinyOpenApiCodegen };
|
|
112
|
+
export { openApiCodegen, tinyOpenApiCodegen };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createContext, use, useMemo } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/lib/config/workspace.context.tsx
|
|
4
|
+
let OpenApiWorkspaceContext;
|
|
5
|
+
(function(_OpenApiWorkspaceContext) {
|
|
6
|
+
const Context = createContext({});
|
|
7
|
+
_OpenApiWorkspaceContext.Provider = ({ values, children }) => {
|
|
8
|
+
const contextValues = useMemo(() => values ?? {}, [values]);
|
|
9
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
10
|
+
value: contextValues,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
_OpenApiWorkspaceContext.useContext = () => {
|
|
15
|
+
return use(Context);
|
|
16
|
+
};
|
|
17
|
+
_OpenApiWorkspaceContext.resolveParam = (context, name, value) => {
|
|
18
|
+
if (value != null) return value;
|
|
19
|
+
const workspaceValue = context[name];
|
|
20
|
+
if (workspaceValue == null) throw new Error(`Missing workspace context param "${name}"`);
|
|
21
|
+
return workspaceValue;
|
|
22
|
+
};
|
|
23
|
+
})(OpenApiWorkspaceContext || (OpenApiWorkspaceContext = {}));
|
|
24
|
+
const useWorkspaceContext = () => OpenApiWorkspaceContext.useContext();
|
|
25
|
+
//#endregion
|
|
26
|
+
export { useWorkspaceContext as n, OpenApiWorkspaceContext as t };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
//#region src/lib/config/router.context.d.ts
|
|
3
|
+
interface RouterProviderProps {
|
|
4
|
+
replace: (url: string) => void;
|
|
5
|
+
}
|
|
6
|
+
declare namespace OpenApiRouter {
|
|
7
|
+
const Provider: ({ children, replace }: PropsWithChildren<RouterProviderProps>) => import("react").JSX.Element;
|
|
8
|
+
const useRouter: () => RouterProviderProps;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/lib/config/workspace.context.d.ts
|
|
12
|
+
type WorkspaceValues = Record<string, unknown>;
|
|
13
|
+
interface WorkspaceProviderProps {
|
|
14
|
+
values?: WorkspaceValues;
|
|
15
|
+
}
|
|
16
|
+
declare namespace OpenApiWorkspaceContext {
|
|
17
|
+
const Provider: ({ values, children }: PropsWithChildren<WorkspaceProviderProps>) => import("react").JSX.Element;
|
|
18
|
+
const useContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
|
|
19
|
+
const resolveParam: <T>(context: WorkspaceValues, name: string, value: T | null | undefined) => T;
|
|
20
|
+
}
|
|
21
|
+
declare const useWorkspaceContext: <TValues extends WorkspaceValues = WorkspaceValues>() => TValues;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { useWorkspaceContext as n, OpenApiRouter as r, OpenApiWorkspaceContext as t };
|
package/dist/zod.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-LPEPQV1V.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/zod.d.ts
|
|
5
4
|
declare namespace ZodExtended {
|
|
6
5
|
interface ParseOptions {
|
|
@@ -8,11 +7,7 @@ declare namespace ZodExtended {
|
|
|
8
7
|
name?: string;
|
|
9
8
|
errorHandler?: ErrorHandler<never>;
|
|
10
9
|
}
|
|
11
|
-
export function parse<ZOutput, ZInput>(schema: z.ZodType<ZOutput, ZInput>, data: unknown, {
|
|
12
|
-
type,
|
|
13
|
-
name,
|
|
14
|
-
errorHandler
|
|
15
|
-
}?: ParseOptions): ZOutput;
|
|
10
|
+
export function parse<ZOutput, ZInput>(schema: z.ZodType<ZOutput, ZInput>, data: unknown, { type, name, errorHandler }?: ParseOptions): ZOutput;
|
|
16
11
|
export const sortExp: (enumSchema: z.ZodEnum) => z.ZodString;
|
|
17
12
|
export {};
|
|
18
13
|
}
|
package/dist/zod.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-BeydPL7s.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/zod.ts
|
|
5
4
|
let ZodExtended;
|
|
6
5
|
(function(_ZodExtended) {
|
|
@@ -28,6 +27,5 @@ let ZodExtended;
|
|
|
28
27
|
});
|
|
29
28
|
});
|
|
30
29
|
})(ZodExtended || (ZodExtended = {}));
|
|
31
|
-
|
|
32
30
|
//#endregion
|
|
33
|
-
export { ZodExtended };
|
|
31
|
+
export { ZodExtended };
|
package/package.json
CHANGED
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
"src/assets/**"
|
|
24
24
|
],
|
|
25
25
|
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
26
27
|
"main": "./dist/index.mjs",
|
|
28
|
+
"module": "./dist/index.mjs",
|
|
27
29
|
"types": "./dist/index.d.mts",
|
|
28
30
|
"exports": {
|
|
29
31
|
".": {
|
|
@@ -54,63 +56,96 @@
|
|
|
54
56
|
"./zod": {
|
|
55
57
|
"types": "./dist/zod.d.mts",
|
|
56
58
|
"import": "./dist/zod.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./native": {
|
|
61
|
+
"types": "./dist/native.d.mts",
|
|
62
|
+
"import": "./dist/native.mjs"
|
|
63
|
+
},
|
|
64
|
+
"./rest": {
|
|
65
|
+
"types": "./dist/rest.d.mts",
|
|
66
|
+
"import": "./dist/rest.mjs"
|
|
67
|
+
},
|
|
68
|
+
"./axios": {
|
|
69
|
+
"types": "./dist/axios.d.mts",
|
|
70
|
+
"import": "./dist/axios.mjs"
|
|
71
|
+
},
|
|
72
|
+
"./errors": {
|
|
73
|
+
"types": "./dist/errors.d.mts",
|
|
74
|
+
"import": "./dist/errors.mjs"
|
|
75
|
+
},
|
|
76
|
+
"./query": {
|
|
77
|
+
"types": "./dist/query.d.mts",
|
|
78
|
+
"import": "./dist/query.mjs"
|
|
79
|
+
},
|
|
80
|
+
"./config": {
|
|
81
|
+
"types": "./dist/config.d.mts",
|
|
82
|
+
"import": "./dist/config.mjs"
|
|
83
|
+
},
|
|
84
|
+
"./auth": {
|
|
85
|
+
"types": "./dist/auth.d.mts",
|
|
86
|
+
"import": "./dist/auth.mjs"
|
|
57
87
|
}
|
|
58
88
|
},
|
|
59
89
|
"scripts": {
|
|
60
|
-
"start": "
|
|
61
|
-
"test": "
|
|
90
|
+
"start": "bun ./src/sh.ts",
|
|
91
|
+
"test": "bun run build:native && bun run test:ts && bun run test:native",
|
|
92
|
+
"test:ts": "OPENAPI_CODEGEN_NATIVE=0 vitest run",
|
|
93
|
+
"test:native": "OPENAPI_CODEGEN_NATIVE=1 OPENAPI_CODEGEN_REQUIRE_FULL_NATIVE=1 vitest run",
|
|
62
94
|
"test:watch": "vitest",
|
|
63
|
-
"build": "tsdown",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
95
|
+
"build": "tsdown && bun run build:native",
|
|
96
|
+
"build:ts": "tsdown",
|
|
97
|
+
"build:native": "bun ./scripts/build-native.mjs",
|
|
98
|
+
"start:dist": "bun ./dist/sh.mjs",
|
|
99
|
+
"gen:base": "rm -rf ./test/generated/base && mkdir -p ./test/generated/base && bun run start generate --config ./test/config.mjs --output ./test/generated/base --no-prettier",
|
|
100
|
+
"gen:next": "rm -rf ./test/generated/next && mkdir -p ./test/generated/next && bun run start generate --config ./test/config.mjs --output ./test/generated/next --no-prettier",
|
|
67
101
|
"test:generated-eq": "vitest run ./src/generators/generated-output-eq.test.ts",
|
|
68
|
-
"gen:verify": "
|
|
102
|
+
"gen:verify": "bun run gen:base && bun run gen:next && bun run test:generated-eq",
|
|
69
103
|
"typecheck": "tsc --noEmit",
|
|
70
104
|
"lint": "oxlint --type-aware --fix",
|
|
71
105
|
"lint:check": "oxlint --type-aware",
|
|
72
106
|
"format": "oxfmt",
|
|
73
107
|
"format:check": "oxfmt --check",
|
|
74
|
-
"check": "
|
|
75
|
-
"push": "
|
|
76
|
-
"dev:generate": "rm -rf ./output &&
|
|
77
|
-
"dev:check": "
|
|
78
|
-
"snapshot:openapi-localhost": "
|
|
79
|
-
"bench:vite-codegen": "
|
|
108
|
+
"check": "bun run typecheck && bun run lint && bun run test",
|
|
109
|
+
"push": "bun ./scripts/publish.mjs",
|
|
110
|
+
"dev:generate": "rm -rf ./output && bun run start generate --config ./test/config.mjs",
|
|
111
|
+
"dev:check": "bun run start check --config ./test/config.mjs",
|
|
112
|
+
"snapshot:openapi-localhost": "bun ./scripts/snapshot-openapi-localhost.mjs",
|
|
113
|
+
"bench:vite-codegen": "bun ./scripts/benchmark-vite-codegen.mjs",
|
|
114
|
+
"verify:tree-shaking": "bun run build:ts && bun ./scripts/verify-tree-shaking.mjs"
|
|
80
115
|
},
|
|
81
116
|
"dependencies": {
|
|
82
|
-
"@apidevtools/swagger-parser": "^10.1.0",
|
|
83
117
|
"@orpc/contract": "^1.14.3",
|
|
84
118
|
"@orpc/openapi": "^1.14.3",
|
|
85
119
|
"@orpc/zod": "^1.14.3",
|
|
86
|
-
"import-fresh": "^3.3.1",
|
|
87
120
|
"openapi-types": "^12.1.3",
|
|
88
121
|
"prompt-sync": "^4.2.0",
|
|
89
122
|
"reflect-metadata": "^0.2.2",
|
|
90
|
-
"
|
|
91
|
-
"typescript": "^5.9.3",
|
|
123
|
+
"yaml": "^2.9.0",
|
|
92
124
|
"yargs": "^18.0.0"
|
|
93
125
|
},
|
|
94
126
|
"devDependencies": {
|
|
95
|
-
"@casl/ability": "
|
|
96
|
-
"@casl/react": "
|
|
127
|
+
"@casl/ability": "6.8.0",
|
|
128
|
+
"@casl/react": "5.0.1",
|
|
97
129
|
"@tanstack/react-query": "~5.90.21",
|
|
130
|
+
"@types/bun": "1.3.14",
|
|
98
131
|
"@types/node": "^25.3.0",
|
|
99
132
|
"@types/prompt-sync": "^4.2.3",
|
|
100
133
|
"@types/react": "^19.2.14",
|
|
101
134
|
"@types/yargs": "^17.0.35",
|
|
102
135
|
"@vitejs/plugin-react": "^5.1.4",
|
|
136
|
+
"axios": "^1.13.1",
|
|
137
|
+
"i18next": "^25.8.11",
|
|
103
138
|
"oxfmt": "^0.34.0",
|
|
104
|
-
"oxlint": "
|
|
139
|
+
"oxlint": "1.50.0",
|
|
105
140
|
"oxlint-tsgolint": "^0.15.0",
|
|
106
141
|
"react": "^19.2.4",
|
|
107
|
-
"tsdown": "^0.
|
|
142
|
+
"tsdown": "^0.22.14",
|
|
108
143
|
"tsx": "^4.21.0",
|
|
109
144
|
"type-fest": "^5.4.4",
|
|
145
|
+
"typescript": "^7.0.2",
|
|
110
146
|
"vite": "npm:rolldown-vite@^7.3.1",
|
|
111
147
|
"vite-plugin-dts": "^4.5.4",
|
|
112
148
|
"vitest": "4.0.18",
|
|
113
|
-
"yargs": "^17.7.2",
|
|
114
149
|
"zod": "^4.3.6"
|
|
115
150
|
},
|
|
116
151
|
"peerDependencies": {
|
|
@@ -130,14 +165,26 @@
|
|
|
130
165
|
"@casl/react": {
|
|
131
166
|
"optional": true
|
|
132
167
|
},
|
|
168
|
+
"@tanstack/react-query": {
|
|
169
|
+
"optional": true
|
|
170
|
+
},
|
|
171
|
+
"axios": {
|
|
172
|
+
"optional": true
|
|
173
|
+
},
|
|
174
|
+
"i18next": {
|
|
175
|
+
"optional": true
|
|
176
|
+
},
|
|
177
|
+
"react": {
|
|
178
|
+
"optional": true
|
|
179
|
+
},
|
|
133
180
|
"vite": {
|
|
134
181
|
"optional": true
|
|
135
182
|
}
|
|
136
183
|
},
|
|
137
184
|
"engines": {
|
|
138
|
-
"
|
|
139
|
-
"
|
|
185
|
+
"bun": ">= 1.3.14",
|
|
186
|
+
"node": ">= 18"
|
|
140
187
|
},
|
|
141
|
-
"packageManager": "
|
|
142
|
-
"version": "3.
|
|
188
|
+
"packageManager": "bun@1.3.14",
|
|
189
|
+
"version": "3.2.0-rc.10"
|
|
143
190
|
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { S as Profiler, h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-DseBECa-.mjs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
|
-
|
|
5
|
-
//#region src/generators/core/resolveConfig.ts
|
|
6
|
-
function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
|
|
7
|
-
const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
|
|
8
|
-
...options,
|
|
9
|
-
includeTags: includeTags?.split(","),
|
|
10
|
-
excludeTags: excludeTags?.split(","),
|
|
11
|
-
inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
|
|
12
|
-
workspaceContext: workspaceContext?.split(",")
|
|
13
|
-
});
|
|
14
|
-
resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
|
|
15
|
-
resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
|
|
16
|
-
return resolvedConfig;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/generators/run/generate.runner.ts
|
|
21
|
-
async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
|
|
22
|
-
const config = profiler.runSync("config.resolve", () => resolveConfig({
|
|
23
|
-
fileConfig,
|
|
24
|
-
params: params ?? {}
|
|
25
|
-
}));
|
|
26
|
-
const openApiDoc = await getOpenApiDoc(config.input, profiler);
|
|
27
|
-
const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
|
|
28
|
-
if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
|
|
29
|
-
removeStaleGeneratedFiles({
|
|
30
|
-
output: config.output,
|
|
31
|
-
filesData,
|
|
32
|
-
options: config
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
await profiler.runAsync("files.write", async () => {
|
|
36
|
-
await writeGenerateFileData(filesData, { formatGeneratedFile });
|
|
37
|
-
});
|
|
38
|
-
return {
|
|
39
|
-
skipped: false,
|
|
40
|
-
config,
|
|
41
|
-
stats: getGenerateStats(filesData, config)
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async function getOpenApiDoc(input, profiler) {
|
|
45
|
-
const parsedDoc = await profiler.runAsync("openapi.parse", async () => await SwaggerParser.parse(input));
|
|
46
|
-
if (!profiler.runSync("openapi.detectExternalRefs", () => hasExternalRef(parsedDoc))) return parsedDoc;
|
|
47
|
-
return await profiler.runAsync("openapi.bundle", async () => await SwaggerParser.bundle(input));
|
|
48
|
-
}
|
|
49
|
-
function hasExternalRef(value) {
|
|
50
|
-
const stack = [value];
|
|
51
|
-
const visited = /* @__PURE__ */ new Set();
|
|
52
|
-
while (stack.length > 0) {
|
|
53
|
-
const current = stack.pop();
|
|
54
|
-
if (!current || typeof current !== "object") continue;
|
|
55
|
-
if (visited.has(current)) continue;
|
|
56
|
-
visited.add(current);
|
|
57
|
-
if ("$ref" in current && typeof current.$ref === "string" && !current.$ref.startsWith("#/")) return true;
|
|
58
|
-
for (const nested of Object.values(current)) if (nested && typeof nested === "object") stack.push(nested);
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
function getGenerateStats(filesData, config) {
|
|
63
|
-
const generatedFilesCount = filesData.length;
|
|
64
|
-
if (generatedFilesCount === 0) return {
|
|
65
|
-
generatedFilesCount,
|
|
66
|
-
generatedModulesCount: 0
|
|
67
|
-
};
|
|
68
|
-
if (!config.splitByTags) return {
|
|
69
|
-
generatedFilesCount,
|
|
70
|
-
generatedModulesCount: 1
|
|
71
|
-
};
|
|
72
|
-
const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
|
|
73
|
-
const modules = /* @__PURE__ */ new Set();
|
|
74
|
-
for (const file of filesData) {
|
|
75
|
-
const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
|
|
76
|
-
if (segments.length < 2) continue;
|
|
77
|
-
const moduleName = segments[0];
|
|
78
|
-
const fileName = segments[segments.length - 1];
|
|
79
|
-
if (!fileName.startsWith(`${moduleName}.`)) continue;
|
|
80
|
-
const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
|
|
81
|
-
if (moduleSuffixes.has(suffix)) modules.add(moduleName);
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
generatedFilesCount,
|
|
85
|
-
generatedModulesCount: modules.size
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
|
-
export { resolveConfig as n, runGenerate as t };
|