@povio/openapi-codegen-cli 3.2.0-rc.9 → 3.3.0-rc.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/README.md +2 -51
- package/dist/acl.d.mts +19 -6
- package/dist/acl.mjs +7 -7
- package/dist/{auth.context-COWO6ssl.mjs → auth.context-BAz8frX9.mjs} +18 -1
- package/dist/{config-DgrOddSC.d.mts → config-BQqze8rU.d.mts} +2 -1
- package/dist/{error-handling-BeydPL7s.mjs → error-handling-CsnufAil.mjs} +45 -21
- package/dist/{error-handling-LPEPQV1V.d.mts → error-handling-D6ZYITQ3.d.mts} +42 -3
- package/dist/generate.runner-BeCGJ1ar.mjs +87 -0
- package/dist/{generateCodeFromOpenAPIDoc-iEa8YAUQ.cjs → generateCodeFromOpenAPIDoc-KQT4kYxY.mjs} +2340 -1393
- package/dist/generator.d.mts +10 -3
- package/dist/generator.mjs +4 -7
- package/dist/index.d.mts +198 -12
- package/dist/index.mjs +256 -12
- package/dist/metro.cjs +4861 -112
- package/dist/metro.d.mts +4 -3
- package/dist/metro.mjs +3 -3
- package/dist/{openapi-codegen.runner-6Yth6QZC.mjs → openapi-codegen.runner-nPBssrBL.mjs} +2 -3
- package/dist/{openapi-source.runner-BZ6ZLgRO.mjs → openapi-source.runner-8kCe-g9S.mjs} +6 -18
- package/dist/{openapi-source.runner-ykstqlPC.d.mts → openapi-source.runner-B6KKrXw7.d.mts} +8 -2
- package/dist/{options-KPf-Fti5.d.mts → options-DdQJ9BSc.d.mts} +1 -6
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +53 -37
- package/dist/tiny.d.mts +1 -1
- package/dist/tiny.mjs +1 -1
- package/dist/vite.d.mts +4 -3
- package/dist/vite.mjs +4 -5
- package/dist/zod.d.mts +7 -2
- package/dist/zod.mjs +1 -1
- package/package.json +22 -69
- package/dist/AuthGuard-GbtTDXs0.d.mts +0 -32
- package/dist/AuthGuard-qpAtHaBz.mjs +0 -24
- package/dist/auth.d.mts +0 -2
- package/dist/auth.mjs +0 -3
- package/dist/axios.d.mts +0 -2
- package/dist/axios.mjs +0 -2
- package/dist/config.d.mts +0 -4
- package/dist/config.mjs +0 -5
- package/dist/errors.d.mts +0 -3
- package/dist/errors.mjs +0 -2
- package/dist/generate.runner-D8AYuEFm.mjs +0 -184
- package/dist/generate.utils-CT-LA-gX.cjs +0 -2267
- package/dist/generateCodeFromOpenAPIDoc--ufinTug.mjs +0 -2061
- package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +0 -2011
- package/dist/i18n-B_brQh4X.d.mts +0 -38
- package/dist/i18n-D-FesqFb.mjs +0 -36
- package/dist/native-bindings-BTQGSGhU.mjs +0 -1480
- package/dist/native-rest-interceptor-CAWR8H5Y.mjs +0 -208
- package/dist/native-rest-interceptor-Cz6saoq5.d.mts +0 -46
- package/dist/native.d.mts +0 -3
- package/dist/native.mjs +0 -3
- 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/query.d.mts +0 -3
- package/dist/query.mjs +0 -3
- package/dist/queryConfig.context-CRJOgf19.d.mts +0 -22
- package/dist/queryConfig.context-CldQ5YL9.mjs +0 -34
- package/dist/rest-client-CQyFvqYC.d.mts +0 -55
- package/dist/rest-interceptor-D5NCNTm1.mjs +0 -115
- package/dist/rest-transport.types-DM5-qyOJ.d.mts +0 -66
- package/dist/rest-transport.types-DxitRtsB.mjs +0 -11
- package/dist/rest.d.mts +0 -2
- package/dist/rest.mjs +0 -2
- package/dist/rest.utils-rezWAIYL.d.mts +0 -10
- package/dist/router.context-EPlMBk3G.mjs +0 -21
- package/dist/useMutationEffects-DIdL8tlx.d.mts +0 -29
- package/dist/useMutationEffects-PB1fvKWM.mjs +0 -68
- package/dist/workspace.context-XWvQ_7Hg.mjs +0 -26
- package/dist/workspace.context-isVY9ves.d.mts +0 -23
package/README.md
CHANGED
|
@@ -89,8 +89,7 @@ bunx openapi-codegen generate --config my-config.ts
|
|
|
89
89
|
--modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
|
|
90
90
|
--replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
|
|
91
91
|
|
|
92
|
-
--
|
|
93
|
-
--axiosRequestConfig Include transport request config parameters in query hooks (default: false)
|
|
92
|
+
--axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
|
|
94
93
|
--infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
|
|
95
94
|
--mutationEffects Add mutation effects options to mutation hooks (default: true)
|
|
96
95
|
--mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
|
|
@@ -139,7 +138,7 @@ bun install
|
|
|
139
138
|
# run tests
|
|
140
139
|
bun run test
|
|
141
140
|
|
|
142
|
-
# run
|
|
141
|
+
# run sources with tsx
|
|
143
142
|
bun run start --help
|
|
144
143
|
bun run start generate --input ./test/petstore.yaml --verbose
|
|
145
144
|
|
|
@@ -151,58 +150,10 @@ bun run start --help
|
|
|
151
150
|
bun run start:dist generate --input ./test/petstore.yaml --verbose
|
|
152
151
|
```
|
|
153
152
|
|
|
154
|
-
### Native Bun code generation
|
|
155
|
-
|
|
156
|
-
The Bun and Node.js CLIs and the Vite plugin automatically use the bundled Rust code-generation core when a compatible native binary is available. Generated files remain byte-for-byte compatible with the TypeScript implementation, which is retained as the fallback when the addon cannot be loaded.
|
|
157
|
-
|
|
158
|
-
Set `OPENAPI_CODEGEN_NATIVE=0` to force the TypeScript path, or `OPENAPI_CODEGEN_NATIVE=1` to require the native path and fail when its binary is unavailable.
|
|
159
|
-
|
|
160
|
-
Release packages include native binaries for Linux x64, macOS arm64, and Windows x64. Build a binary for the current platform with `bun run build:native`.
|
|
161
|
-
|
|
162
153
|
## Common Issues
|
|
163
154
|
|
|
164
155
|
### App REST Client Interceptors
|
|
165
156
|
|
|
166
|
-
Select the fetch-based client without changing endpoint and query APIs:
|
|
167
|
-
|
|
168
|
-
```ts
|
|
169
|
-
import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
|
|
170
|
-
|
|
171
|
-
export default {
|
|
172
|
-
restClient: "native",
|
|
173
|
-
} satisfies OpenAPICodegenConfig;
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Native mode imports common request/response contracts from `@povio/openapi-codegen-cli/rest` and the concrete
|
|
177
|
-
`NativeRestClient` from `@povio/openapi-codegen-cli/native`. It uses `fetch` for normal requests and uploads, switching
|
|
178
|
-
to `XMLHttpRequest` in browsers only when an upload progress callback is provided.
|
|
179
|
-
|
|
180
|
-
Native interceptors use the common transport interface:
|
|
181
|
-
|
|
182
|
-
```ts
|
|
183
|
-
import { NativeRestClient } from "@povio/openapi-codegen-cli/native";
|
|
184
|
-
import type { RestTransportInterceptor } from "@povio/openapi-codegen-cli/rest";
|
|
185
|
-
|
|
186
|
-
const authorizationInterceptor: RestTransportInterceptor = {
|
|
187
|
-
onRequest(request) {
|
|
188
|
-
request.headers.set("Authorization", `Bearer ${localStorage.getItem("accessToken")}`);
|
|
189
|
-
return request;
|
|
190
|
-
},
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export const AppRestClient = new NativeRestClient({
|
|
194
|
-
config: { baseURL: "https://api.example.com" },
|
|
195
|
-
interceptors: [authorizationInterceptor],
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
Axios remains the default for backward compatibility. The existing Axios interceptor API remains available in Axios
|
|
200
|
-
mode.
|
|
201
|
-
|
|
202
|
-
Native mode does not run the library `ErrorHandler` or create `ApplicationException` values. It throws `HttpError` for
|
|
203
|
-
non-success HTTP responses and preserves Zod, network, cancellation, and timeout errors so applications can handle them
|
|
204
|
-
directly in query callbacks, error boundaries, or their own normalization layer.
|
|
205
|
-
|
|
206
157
|
In order to add interceptors to the used REST client, you must create your own instance of a RestClient and pass your implemented interceptors into the constructor. Make sure to set `restClientImportPath` in your openapi generation configuration too.
|
|
207
158
|
|
|
208
159
|
```ts
|
package/dist/acl.d.mts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-D6ZYITQ3.mjs";
|
|
2
|
+
import * as _$react from "react";
|
|
2
3
|
import { PropsWithChildren } from "react";
|
|
3
4
|
import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
|
|
4
5
|
import { PackRule } from "@casl/ability/extra";
|
|
5
6
|
import { BoundCanProps } from "@casl/react";
|
|
7
|
+
|
|
6
8
|
//#region src/lib/acl/appAbility.types.d.ts
|
|
7
9
|
type AppAbilities = AbilityTuple<string, Subject>;
|
|
8
10
|
type AppAbility = PureAbility<AppAbilities>;
|
|
9
11
|
//#endregion
|
|
10
12
|
//#region src/lib/acl/ability.context.d.ts
|
|
11
13
|
declare namespace AbilityContext {
|
|
12
|
-
export const Consumer:
|
|
14
|
+
export const Consumer: _$react.Consumer<AppAbility>;
|
|
13
15
|
interface ProviderProps {
|
|
14
16
|
user?: {
|
|
15
17
|
aclRules?: PackRule<RawRuleOf<AppAbility>>[];
|
|
16
18
|
} | null;
|
|
17
19
|
}
|
|
18
|
-
export const Provider: ({
|
|
20
|
+
export const Provider: ({
|
|
21
|
+
children
|
|
22
|
+
}: PropsWithChildren<ProviderProps>) => _$react.JSX.Element;
|
|
19
23
|
export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
|
|
20
24
|
export {};
|
|
21
25
|
}
|
|
@@ -25,20 +29,29 @@ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
|
|
|
25
29
|
canUse: TAppAbilities;
|
|
26
30
|
redirectTo?: string;
|
|
27
31
|
}
|
|
28
|
-
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
|
|
32
|
+
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
|
|
33
|
+
canUse,
|
|
34
|
+
redirectTo,
|
|
35
|
+
children
|
|
36
|
+
}: PropsWithChildren<AclGuardProps<TAppAbilities>>) => _$react.ReactNode;
|
|
29
37
|
//#endregion
|
|
30
38
|
//#region src/lib/acl/Can.d.ts
|
|
31
39
|
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
32
40
|
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
33
41
|
use: TAppAbilities;
|
|
34
42
|
} & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
|
|
35
|
-
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
43
|
+
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
44
|
+
use,
|
|
45
|
+
...props
|
|
46
|
+
}: CanProps<TAppAbilities>) => _$react.JSX.Element;
|
|
36
47
|
//#endregion
|
|
37
48
|
//#region src/lib/acl/useAclCheck.d.ts
|
|
38
49
|
interface UseAclCheckProps {
|
|
39
50
|
errorHandler?: ErrorHandler<never>;
|
|
40
51
|
}
|
|
41
|
-
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
52
|
+
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
53
|
+
errorHandler
|
|
54
|
+
}?: UseAclCheckProps): {
|
|
42
55
|
checkAcl: (appAbility: TAppAbilities) => void;
|
|
43
56
|
};
|
|
44
57
|
//#endregion
|
package/dist/acl.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createContext, useCallback, useMemo } from "react";
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-CsnufAil.mjs";
|
|
2
|
+
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-BAz8frX9.mjs";
|
|
3
|
+
import { createContext, useCallback, useEffect, useState } from "react";
|
|
5
4
|
import { jsx } from "react/jsx-runtime";
|
|
6
5
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
7
6
|
import { unpackRules } from "@casl/ability/extra";
|
|
@@ -15,15 +14,16 @@ let AbilityContext;
|
|
|
15
14
|
const { Consumer } = Context;
|
|
16
15
|
_AbilityContext.Consumer = Consumer;
|
|
17
16
|
_AbilityContext.Provider = ({ children }) => {
|
|
17
|
+
const [ability, setAbility] = useState(initialAppAbility);
|
|
18
18
|
const { user } = AuthContext.useAuth();
|
|
19
|
-
|
|
20
|
-
if (!user || !("aclRules" in user)) return
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (!user || !("aclRules" in user)) return;
|
|
21
21
|
const { can, build } = createAppAbilityBuilder();
|
|
22
22
|
const packedRules = user.aclRules;
|
|
23
23
|
unpackRules(packedRules).forEach(({ action, subject, conditions }) => {
|
|
24
24
|
can(action, subject, conditions);
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
setAbility(build());
|
|
27
27
|
}, [user]);
|
|
28
28
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
29
29
|
value: ability,
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import { createContext, use, useMemo } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
//#region src/lib/config/router.context.tsx
|
|
4
|
+
let OpenApiRouter;
|
|
5
|
+
(function(_OpenApiRouter) {
|
|
6
|
+
const Context = createContext(null);
|
|
7
|
+
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
8
|
+
return /* @__PURE__ */ jsx(Context, {
|
|
9
|
+
value: useMemo(() => ({ replace }), [replace]),
|
|
10
|
+
children
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
_OpenApiRouter.useRouter = () => {
|
|
14
|
+
const context = use(Context);
|
|
15
|
+
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
16
|
+
return context;
|
|
17
|
+
};
|
|
18
|
+
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
19
|
+
//#endregion
|
|
3
20
|
//#region src/lib/auth/auth.context.tsx
|
|
4
21
|
let AuthContext;
|
|
5
22
|
(function(_AuthContext) {
|
|
@@ -36,4 +53,4 @@ let AuthContext;
|
|
|
36
53
|
};
|
|
37
54
|
})(AuthContext || (AuthContext = {}));
|
|
38
55
|
//#endregion
|
|
39
|
-
export { AuthContext as t };
|
|
56
|
+
export { OpenApiRouter as n, AuthContext as t };
|
|
@@ -1,26 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
1
|
+
import { isAxiosError, isCancel } from "axios";
|
|
3
2
|
import { z } from "zod";
|
|
4
|
-
//#region src/lib/
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
//#region src/lib/assets/locales/en/translation.json
|
|
4
|
+
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
5
|
+
"dataValidation": "An error occurred while validating the data",
|
|
6
|
+
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
7
|
+
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
8
|
+
"canceledError": "The request was canceled.",
|
|
9
|
+
"unknownError": "An unknown error occurred. Please try again later.",
|
|
10
|
+
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
11
|
+
} } };
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/lib/assets/locales/sl/translation.json
|
|
14
|
+
var translation_default = { openapi: { "sharedErrors": {
|
|
15
|
+
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
16
|
+
"internalError": "Prišlo je do notranje napake.",
|
|
17
|
+
"networkError": "Prišlo je do napake v omrežju.",
|
|
18
|
+
"canceledError": "Zahteva je bila preklicana.",
|
|
19
|
+
"unknownError": "Prišlo je do neznane napake.",
|
|
20
|
+
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
21
|
+
} } };
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/lib/config/i18n.ts
|
|
24
|
+
const ns = "openapi";
|
|
25
|
+
const resources = {
|
|
26
|
+
en: { [ns]: translation_default$1 },
|
|
27
|
+
sl: { [ns]: translation_default }
|
|
28
|
+
};
|
|
29
|
+
let getT = null;
|
|
30
|
+
function configureTranslations(getter) {
|
|
31
|
+
getT = () => getter();
|
|
7
32
|
}
|
|
8
|
-
function
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
return false;
|
|
33
|
+
function resolveT() {
|
|
34
|
+
if (!getT) throw new Error("Translations not configured. Call configureTranslations() at app startup.");
|
|
35
|
+
return getT();
|
|
12
36
|
}
|
|
13
37
|
//#endregion
|
|
14
38
|
//#region src/lib/rest/rest.utils.ts
|
|
15
|
-
function getResponseData(error) {
|
|
16
|
-
if (error instanceof HttpError) return error.response.data;
|
|
17
|
-
return isAxiosErrorLike(error) ? error.response?.data : void 0;
|
|
18
|
-
}
|
|
19
39
|
let RestUtils;
|
|
20
40
|
(function(_RestUtils) {
|
|
21
41
|
_RestUtils.extractServerResponseCode = (e) => {
|
|
22
42
|
if (e instanceof z.ZodError) return "validation-exception";
|
|
23
|
-
|
|
43
|
+
if (!isAxiosError(e)) return null;
|
|
44
|
+
if (!e.response) return null;
|
|
45
|
+
const data = e.response.data;
|
|
24
46
|
if (typeof data?.code === "string") return data.code;
|
|
25
47
|
if (typeof data?.code === "number") return data.code;
|
|
26
48
|
return null;
|
|
@@ -32,7 +54,9 @@ let RestUtils;
|
|
|
32
54
|
};
|
|
33
55
|
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
34
56
|
if (e instanceof z.ZodError) return e.message;
|
|
35
|
-
|
|
57
|
+
if (!isAxiosError(e)) return null;
|
|
58
|
+
if (!e.response) return null;
|
|
59
|
+
const data = e.response.data;
|
|
36
60
|
if (typeof data?.message === "string") return data.message;
|
|
37
61
|
return null;
|
|
38
62
|
};
|
|
@@ -85,8 +109,7 @@ var ErrorHandler = class ErrorHandler {
|
|
|
85
109
|
const internalError = {
|
|
86
110
|
code: "INTERNAL_ERROR",
|
|
87
111
|
condition: (e) => {
|
|
88
|
-
if (
|
|
89
|
-
if (e instanceof HttpError) return e.response.status >= 500 && e.response.status < 600;
|
|
112
|
+
if (isAxiosError(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
90
113
|
return false;
|
|
91
114
|
},
|
|
92
115
|
getMessage: () => resolveT()("openapi.sharedErrors.internalError", { ns })
|
|
@@ -94,8 +117,7 @@ var ErrorHandler = class ErrorHandler {
|
|
|
94
117
|
const networkError = {
|
|
95
118
|
code: "NETWORK_ERROR",
|
|
96
119
|
condition: (e) => {
|
|
97
|
-
if (
|
|
98
|
-
if (e instanceof TypeError) return true;
|
|
120
|
+
if (isAxiosError(e)) return e.code === "ERR_NETWORK";
|
|
99
121
|
return false;
|
|
100
122
|
},
|
|
101
123
|
getMessage: () => resolveT()("openapi.sharedErrors.networkError", { ns })
|
|
@@ -103,7 +125,9 @@ var ErrorHandler = class ErrorHandler {
|
|
|
103
125
|
const canceledError = {
|
|
104
126
|
code: "CANCELED_ERROR",
|
|
105
127
|
condition: (e) => {
|
|
106
|
-
|
|
128
|
+
if (isCancel(e)) return true;
|
|
129
|
+
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
130
|
+
return false;
|
|
107
131
|
},
|
|
108
132
|
getMessage: () => resolveT()("openapi.sharedErrors.canceledError", { ns })
|
|
109
133
|
};
|
|
@@ -181,4 +205,4 @@ var ErrorHandler = class ErrorHandler {
|
|
|
181
205
|
};
|
|
182
206
|
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
183
207
|
//#endregion
|
|
184
|
-
export { RestUtils as a, SharedErrorHandler as i, DomainErrorRegistry as n, ErrorHandler as r, ApplicationException as t };
|
|
208
|
+
export { RestUtils as a, resources as c, SharedErrorHandler as i, DomainErrorRegistry as n, configureTranslations as o, ErrorHandler as r, ns as s, ApplicationException as t };
|
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/lib/config/i18n.d.ts
|
|
2
|
+
declare const ns = "openapi";
|
|
3
|
+
declare const resources: {
|
|
4
|
+
readonly en: {
|
|
5
|
+
readonly openapi: {
|
|
6
|
+
openapi: {
|
|
7
|
+
sharedErrors: {
|
|
8
|
+
dataValidation: string;
|
|
9
|
+
internalError: string;
|
|
10
|
+
networkError: string;
|
|
11
|
+
canceledError: string;
|
|
12
|
+
unknownError: string;
|
|
13
|
+
unknownErrorWithCode: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly sl: {
|
|
19
|
+
readonly openapi: {
|
|
20
|
+
openapi: {
|
|
21
|
+
sharedErrors: {
|
|
22
|
+
dataValidation: string;
|
|
23
|
+
internalError: string;
|
|
24
|
+
networkError: string;
|
|
25
|
+
canceledError: string;
|
|
26
|
+
unknownError: string;
|
|
27
|
+
unknownErrorWithCode: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type TranslateFunction = (key: string, options?: {
|
|
34
|
+
ns?: string;
|
|
35
|
+
}) => string;
|
|
36
|
+
declare function configureTranslations<T>(getter: () => T): void;
|
|
37
|
+
//#endregion
|
|
2
38
|
//#region src/lib/rest/error-handling.d.ts
|
|
3
39
|
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
4
40
|
declare class ApplicationException<CodeT> extends Error {
|
|
@@ -33,7 +69,10 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
33
69
|
private readonly userEntries;
|
|
34
70
|
private readonly generalEntries;
|
|
35
71
|
private onRethrowError?;
|
|
36
|
-
constructor({
|
|
72
|
+
constructor({
|
|
73
|
+
entries,
|
|
74
|
+
onRethrowError
|
|
75
|
+
}: ErrorHandlerOptions<CodeT>);
|
|
37
76
|
private matchesEntry;
|
|
38
77
|
/** Lazy so resolveT() only runs when getMessage actually uses `t`. */
|
|
39
78
|
private static lazyT;
|
|
@@ -44,4 +83,4 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
44
83
|
}
|
|
45
84
|
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
46
85
|
//#endregion
|
|
47
|
-
export { ErrorHandler as a, SharedErrorHandler as c, ErrorEntry as i, DomainErrorEntry as n, ErrorHandlerOptions as o, DomainErrorRegistry as r, GeneralErrorCodes as s, ApplicationException as t };
|
|
86
|
+
export { ErrorHandler as a, SharedErrorHandler as c, ns as d, resources as f, ErrorEntry as i, TranslateFunction as l, DomainErrorEntry as n, ErrorHandlerOptions as o, DomainErrorRegistry as r, GeneralErrorCodes as s, ApplicationException as t, configureTranslations as u };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { h as deepMerge, i as writeGenerateFileData, p as DEFAULT_GENERATE_OPTIONS, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-KQT4kYxY.mjs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
|
+
//#region src/generators/core/resolveConfig.ts
|
|
5
|
+
function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
|
|
6
|
+
const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
|
|
7
|
+
...options,
|
|
8
|
+
includeTags: includeTags?.split(","),
|
|
9
|
+
excludeTags: excludeTags?.split(","),
|
|
10
|
+
inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
|
|
11
|
+
workspaceContext: workspaceContext?.split(",")
|
|
12
|
+
});
|
|
13
|
+
resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
|
|
14
|
+
resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
|
|
15
|
+
return resolvedConfig;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/generators/run/generate.runner.ts
|
|
19
|
+
async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
|
|
20
|
+
const config = profiler.runSync("config.resolve", () => resolveConfig({
|
|
21
|
+
fileConfig,
|
|
22
|
+
params: params ?? {}
|
|
23
|
+
}));
|
|
24
|
+
const openApiDoc = await getOpenApiDoc(config.input, profiler);
|
|
25
|
+
const filesData = profiler.runSync("generate.total", () => generateCodeFromOpenAPIDoc(openApiDoc, config, profiler));
|
|
26
|
+
if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
|
|
27
|
+
removeStaleGeneratedFiles({
|
|
28
|
+
output: config.output,
|
|
29
|
+
filesData,
|
|
30
|
+
options: config
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
await profiler.runAsync("files.write", async () => {
|
|
34
|
+
await writeGenerateFileData(filesData, { formatGeneratedFile });
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
skipped: false,
|
|
38
|
+
config,
|
|
39
|
+
stats: getGenerateStats(filesData, config)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async function getOpenApiDoc(input, profiler) {
|
|
43
|
+
const parsedDoc = await profiler.runAsync("openapi.parse", async () => await SwaggerParser.parse(input));
|
|
44
|
+
if (!profiler.runSync("openapi.detectExternalRefs", () => hasExternalRef(parsedDoc))) return parsedDoc;
|
|
45
|
+
return await profiler.runAsync("openapi.bundle", async () => await SwaggerParser.bundle(input));
|
|
46
|
+
}
|
|
47
|
+
function hasExternalRef(value) {
|
|
48
|
+
const stack = [value];
|
|
49
|
+
const visited = /* @__PURE__ */ new Set();
|
|
50
|
+
while (stack.length > 0) {
|
|
51
|
+
const current = stack.pop();
|
|
52
|
+
if (!current || typeof current !== "object") continue;
|
|
53
|
+
if (visited.has(current)) continue;
|
|
54
|
+
visited.add(current);
|
|
55
|
+
if ("$ref" in current && typeof current.$ref === "string" && !current.$ref.startsWith("#/")) return true;
|
|
56
|
+
for (const nested of Object.values(current)) if (nested && typeof nested === "object") stack.push(nested);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function getGenerateStats(filesData, config) {
|
|
61
|
+
const generatedFilesCount = filesData.length;
|
|
62
|
+
if (generatedFilesCount === 0) return {
|
|
63
|
+
generatedFilesCount,
|
|
64
|
+
generatedModulesCount: 0
|
|
65
|
+
};
|
|
66
|
+
if (!config.splitByTags) return {
|
|
67
|
+
generatedFilesCount,
|
|
68
|
+
generatedModulesCount: 1
|
|
69
|
+
};
|
|
70
|
+
const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
|
|
71
|
+
const modules = /* @__PURE__ */ new Set();
|
|
72
|
+
for (const file of filesData) {
|
|
73
|
+
const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
|
|
74
|
+
if (segments.length < 2) continue;
|
|
75
|
+
const moduleName = segments[0];
|
|
76
|
+
const fileName = segments[segments.length - 1];
|
|
77
|
+
if (!fileName.startsWith(`${moduleName}.`)) continue;
|
|
78
|
+
const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
|
|
79
|
+
if (moduleSuffixes.has(suffix)) modules.add(moduleName);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
generatedFilesCount,
|
|
83
|
+
generatedModulesCount: modules.size
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
export { resolveConfig as n, runGenerate as t };
|