@povio/openapi-codegen-cli 3.1.0-rc.7 → 3.2.0-rc.2
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 +21 -14
- package/dist/acl.d.mts +6 -20
- package/dist/acl.mjs +3 -8
- package/dist/{auth.context-Bu5KW2sI.mjs → auth.context-YFWzkwoN.mjs} +3 -5
- package/dist/{config-BU7wVf7U.d.mts → config-DFpV8mjG.d.mts} +1 -2
- package/dist/{error-handling-BeRxGbwE.d.mts → error-handling-CNOHs4Fc.d.mts} +3 -4
- package/dist/{error-handling-DG8SfTWB.mjs → error-handling-DDIXMA-R.mjs} +8 -11
- package/dist/generate.runner-BGhsnDm8.mjs +1674 -0
- package/dist/generate.utils-C29zzyBl.cjs +2281 -0
- package/dist/{generateCodeFromOpenAPIDoc-CbQ9gQss.mjs → generateCodeFromOpenAPIDoc-B0Cmn2dx.cjs} +1261 -2336
- package/dist/generateCodeFromOpenAPIDoc-CLQbTTwF.mjs +2004 -0
- package/dist/generator.d.mts +3 -10
- package/dist/generator.mjs +8 -9
- package/dist/getDataFromOpenAPIDoc-fPRPa4_t.mjs +1988 -0
- package/dist/index.d.mts +9 -48
- package/dist/index.mjs +4 -11
- package/dist/metro.cjs +114 -4923
- package/dist/metro.d.mts +3 -4
- package/dist/metro.mjs +4 -9
- 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-BqOhUduF.mjs → openapi-codegen.runner-BtaqQSH2.mjs} +3 -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-zPcbJwpP.d.mts} +2 -8
- package/dist/{options-CE4Koxof.d.mts → options-DtAnhCLZ.d.mts} +3 -1
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +25 -71
- package/dist/tiny.d.mts +1 -3
- package/dist/tiny.mjs +2 -3
- package/dist/vite.d.mts +3 -4
- package/dist/vite.mjs +6 -10
- package/dist/zod.d.mts +2 -7
- package/dist/zod.mjs +2 -4
- package/package.json +28 -26
- package/dist/generate.runner-DnUDkoAZ.mjs +0 -90
package/README.md
CHANGED
|
@@ -13,13 +13,13 @@ The tool partially leverages code from [openapi-zod-client](https://github.com/a
|
|
|
13
13
|
## Setup
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
bun add @povio/openapi-codegen-cli
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Example
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
|
|
22
|
+
bunx openapi-codegen generate --input http://localhost:3001/docs-json
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
## Configuration Files
|
|
@@ -46,7 +46,7 @@ export default config;
|
|
|
46
46
|
Then run without arguments:
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
|
-
|
|
49
|
+
bunx openapi-codegen generate
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
### Configuration File Discovery
|
|
@@ -58,7 +58,7 @@ The CLI automatically searches for the TypeScript configuration file:
|
|
|
58
58
|
You can also specify a custom configuration file:
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
|
-
|
|
61
|
+
bunx openapi-codegen generate --config my-config.ts
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
## Options
|
|
@@ -132,25 +132,32 @@ yarn openapi-codegen generate --config my-config.ts
|
|
|
132
132
|
#### Test locally
|
|
133
133
|
|
|
134
134
|
```bash
|
|
135
|
-
#
|
|
136
|
-
|
|
137
|
-
yarn
|
|
135
|
+
# install dependencies
|
|
136
|
+
bun install
|
|
138
137
|
|
|
139
138
|
# run tests
|
|
140
|
-
|
|
139
|
+
bun run test
|
|
141
140
|
|
|
142
|
-
# run sources with
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
# run TypeScript sources directly with Bun
|
|
142
|
+
bun run start --help
|
|
143
|
+
bun run start generate --input ./test/petstore.yaml --verbose
|
|
145
144
|
|
|
146
145
|
# build new version
|
|
147
|
-
|
|
146
|
+
bun run build
|
|
148
147
|
|
|
149
148
|
# test build
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
bun run start --help
|
|
150
|
+
bun run start:dist generate --input ./test/petstore.yaml --verbose
|
|
152
151
|
```
|
|
153
152
|
|
|
153
|
+
### Native Bun code generation
|
|
154
|
+
|
|
155
|
+
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.
|
|
156
|
+
|
|
157
|
+
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.
|
|
158
|
+
|
|
159
|
+
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`.
|
|
160
|
+
|
|
154
161
|
## Common Issues
|
|
155
162
|
|
|
156
163
|
### App REST Client Interceptors
|
package/dist/acl.d.mts
CHANGED
|
@@ -1,26 +1,21 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
2
|
-
import * as react from "react";
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-CNOHs4Fc.mjs";
|
|
3
2
|
import { PropsWithChildren } from "react";
|
|
4
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
3
|
import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
|
|
6
4
|
import { PackRule } from "@casl/ability/extra";
|
|
7
5
|
import { BoundCanProps } from "@casl/react";
|
|
8
|
-
|
|
9
6
|
//#region src/lib/acl/appAbility.types.d.ts
|
|
10
7
|
type AppAbilities = AbilityTuple<string, Subject>;
|
|
11
8
|
type AppAbility = PureAbility<AppAbilities>;
|
|
12
9
|
//#endregion
|
|
13
10
|
//#region src/lib/acl/ability.context.d.ts
|
|
14
11
|
declare namespace AbilityContext {
|
|
15
|
-
export const Consumer: react.Consumer<AppAbility>;
|
|
12
|
+
export const Consumer: import("react").Consumer<AppAbility>;
|
|
16
13
|
interface ProviderProps {
|
|
17
14
|
user?: {
|
|
18
15
|
aclRules?: PackRule<RawRuleOf<AppAbility>>[];
|
|
19
16
|
} | null;
|
|
20
17
|
}
|
|
21
|
-
export const Provider: ({
|
|
22
|
-
children
|
|
23
|
-
}: PropsWithChildren<ProviderProps>) => react_jsx_runtime0.JSX.Element;
|
|
18
|
+
export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react").JSX.Element;
|
|
24
19
|
export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
|
|
25
20
|
export {};
|
|
26
21
|
}
|
|
@@ -30,29 +25,20 @@ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
|
|
|
30
25
|
canUse: TAppAbilities;
|
|
31
26
|
redirectTo?: string;
|
|
32
27
|
}
|
|
33
|
-
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
|
|
34
|
-
canUse,
|
|
35
|
-
redirectTo,
|
|
36
|
-
children
|
|
37
|
-
}: PropsWithChildren<AclGuardProps<TAppAbilities>>) => react.ReactNode;
|
|
28
|
+
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import("react").ReactNode;
|
|
38
29
|
//#endregion
|
|
39
30
|
//#region src/lib/acl/Can.d.ts
|
|
40
31
|
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
41
32
|
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
42
33
|
use: TAppAbilities;
|
|
43
34
|
} & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
|
|
44
|
-
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
45
|
-
use,
|
|
46
|
-
...props
|
|
47
|
-
}: CanProps<TAppAbilities>) => react_jsx_runtime0.JSX.Element;
|
|
35
|
+
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react").JSX.Element;
|
|
48
36
|
//#endregion
|
|
49
37
|
//#region src/lib/acl/useAclCheck.d.ts
|
|
50
38
|
interface UseAclCheckProps {
|
|
51
39
|
errorHandler?: ErrorHandler<never>;
|
|
52
40
|
}
|
|
53
|
-
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
54
|
-
errorHandler
|
|
55
|
-
}?: UseAclCheckProps): {
|
|
41
|
+
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({ errorHandler }?: UseAclCheckProps): {
|
|
56
42
|
checkAcl: (appAbility: TAppAbilities) => void;
|
|
57
43
|
};
|
|
58
44
|
//#endregion
|
package/dist/acl.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
2
|
-
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-DDIXMA-R.mjs";
|
|
2
|
+
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-YFWzkwoN.mjs";
|
|
3
3
|
import { createContext, useCallback, useEffect, useState } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
6
6
|
import { unpackRules } from "@casl/ability/extra";
|
|
7
7
|
import { createContextualCan, useAbility } from "@casl/react";
|
|
8
|
-
|
|
9
8
|
//#region src/lib/acl/ability.context.tsx
|
|
10
9
|
let AbilityContext;
|
|
11
10
|
(function(_AbilityContext) {
|
|
@@ -35,7 +34,6 @@ let AbilityContext;
|
|
|
35
34
|
return useAbility(Context);
|
|
36
35
|
};
|
|
37
36
|
})(AbilityContext || (AbilityContext = {}));
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
//#region src/lib/acl/AclGuard.tsx
|
|
41
39
|
const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
|
|
@@ -47,7 +45,6 @@ const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
|
|
|
47
45
|
}
|
|
48
46
|
return children;
|
|
49
47
|
};
|
|
50
|
-
|
|
51
48
|
//#endregion
|
|
52
49
|
//#region src/lib/acl/Can.tsx
|
|
53
50
|
const ContextualCan = createContextualCan(AbilityContext.Consumer);
|
|
@@ -59,7 +56,6 @@ const Can = ({ use, ...props }) => {
|
|
|
59
56
|
on: subject
|
|
60
57
|
});
|
|
61
58
|
};
|
|
62
|
-
|
|
63
59
|
//#endregion
|
|
64
60
|
//#region src/lib/acl/useAclCheck.ts
|
|
65
61
|
function useAclCheck({ errorHandler } = {}) {
|
|
@@ -69,6 +65,5 @@ function useAclCheck({ errorHandler } = {}) {
|
|
|
69
65
|
if (!ability.can(action, subject)) (errorHandler ?? SharedErrorHandler).rethrowError(/* @__PURE__ */ new Error("ACL check failed"));
|
|
70
66
|
}, [ability, errorHandler]) };
|
|
71
67
|
}
|
|
72
|
-
|
|
73
68
|
//#endregion
|
|
74
|
-
export { AbilityContext, Can, createAclGuard, useAclCheck };
|
|
69
|
+
export { AbilityContext, Can, createAclGuard, useAclCheck };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createContext, use, useMemo } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
4
3
|
//#region src/lib/config/router.context.tsx
|
|
5
4
|
let OpenApiRouter;
|
|
6
5
|
(function(_OpenApiRouter) {
|
|
7
6
|
const Context = createContext(null);
|
|
8
7
|
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
8
|
+
const value = useMemo(() => ({ replace }), [replace]);
|
|
9
9
|
return /* @__PURE__ */ jsx(Context, {
|
|
10
|
-
value
|
|
10
|
+
value,
|
|
11
11
|
children
|
|
12
12
|
});
|
|
13
13
|
};
|
|
@@ -17,7 +17,6 @@ let OpenApiRouter;
|
|
|
17
17
|
return context;
|
|
18
18
|
};
|
|
19
19
|
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
20
|
-
|
|
21
20
|
//#endregion
|
|
22
21
|
//#region src/lib/auth/auth.context.tsx
|
|
23
22
|
let AuthContext;
|
|
@@ -54,6 +53,5 @@ let AuthContext;
|
|
|
54
53
|
return use(Context);
|
|
55
54
|
};
|
|
56
55
|
})(AuthContext || (AuthContext = {}));
|
|
57
|
-
|
|
58
56
|
//#endregion
|
|
59
|
-
export { OpenApiRouter as n, AuthContext as t };
|
|
57
|
+
export { OpenApiRouter as n, AuthContext as t };
|
|
@@ -69,11 +69,10 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
69
69
|
private readonly userEntries;
|
|
70
70
|
private readonly generalEntries;
|
|
71
71
|
private onRethrowError?;
|
|
72
|
-
constructor({
|
|
73
|
-
entries,
|
|
74
|
-
onRethrowError
|
|
75
|
-
}: ErrorHandlerOptions<CodeT>);
|
|
72
|
+
constructor({ entries, onRethrowError }: ErrorHandlerOptions<CodeT>);
|
|
76
73
|
private matchesEntry;
|
|
74
|
+
/** Lazy so resolveT() only runs when getMessage actually uses `t`. */
|
|
75
|
+
private static lazyT;
|
|
77
76
|
rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
|
|
78
77
|
getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
|
|
79
78
|
getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isAxiosError, isCancel } from "axios";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/lib/assets/locales/en/translation.json
|
|
5
4
|
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
6
5
|
"dataValidation": "An error occurred while validating the data",
|
|
@@ -10,7 +9,6 @@ var translation_default$1 = { openapi: { "sharedErrors": {
|
|
|
10
9
|
"unknownError": "An unknown error occurred. Please try again later.",
|
|
11
10
|
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
12
11
|
} } };
|
|
13
|
-
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region src/lib/assets/locales/sl/translation.json
|
|
16
14
|
var translation_default = { openapi: { "sharedErrors": {
|
|
@@ -21,7 +19,6 @@ var translation_default = { openapi: { "sharedErrors": {
|
|
|
21
19
|
"unknownError": "Prišlo je do neznane napake.",
|
|
22
20
|
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
23
21
|
} } };
|
|
24
|
-
|
|
25
22
|
//#endregion
|
|
26
23
|
//#region src/lib/config/i18n.ts
|
|
27
24
|
const ns = "openapi";
|
|
@@ -37,7 +34,6 @@ function resolveT() {
|
|
|
37
34
|
if (!getT) throw new Error("Translations not configured. Call configureTranslations() at app startup.");
|
|
38
35
|
return getT();
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
//#endregion
|
|
42
38
|
//#region src/lib/rest/rest.utils.ts
|
|
43
39
|
let RestUtils;
|
|
@@ -69,7 +65,6 @@ let RestUtils;
|
|
|
69
65
|
return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
70
66
|
};
|
|
71
67
|
})(RestUtils || (RestUtils = {}));
|
|
72
|
-
|
|
73
68
|
//#endregion
|
|
74
69
|
//#region src/lib/rest/error-handling.ts
|
|
75
70
|
var ApplicationException = class extends Error {
|
|
@@ -97,7 +92,7 @@ var DomainErrorRegistry = class {
|
|
|
97
92
|
return this.entries.get(code);
|
|
98
93
|
}
|
|
99
94
|
};
|
|
100
|
-
var ErrorHandler = class {
|
|
95
|
+
var ErrorHandler = class ErrorHandler {
|
|
101
96
|
entries = [];
|
|
102
97
|
userEntries;
|
|
103
98
|
generalEntries;
|
|
@@ -164,25 +159,28 @@ var ErrorHandler = class {
|
|
|
164
159
|
if (entry.condition) return entry.condition(error);
|
|
165
160
|
return code === entry.code;
|
|
166
161
|
}
|
|
162
|
+
/** Lazy so resolveT() only runs when getMessage actually uses `t`. */
|
|
163
|
+
static lazyT = (key, options) => resolveT()(key, options);
|
|
167
164
|
rethrowError(error) {
|
|
168
165
|
const code = RestUtils.extractServerResponseCode(error);
|
|
169
166
|
const serverMessage = RestUtils.extractServerErrorMessage(error);
|
|
167
|
+
const t = ErrorHandler.lazyT;
|
|
170
168
|
const userEntry = this.userEntries.find((entry) => this.matchesEntry(error, entry, code));
|
|
171
169
|
if (userEntry) {
|
|
172
|
-
const exception = new ApplicationException(userEntry.getMessage(
|
|
170
|
+
const exception = new ApplicationException(userEntry.getMessage(t, error), userEntry.code, serverMessage);
|
|
173
171
|
this.onRethrowError?.(error, exception);
|
|
174
172
|
throw exception;
|
|
175
173
|
}
|
|
176
174
|
if (code !== null) {
|
|
177
175
|
const registryEntry = DomainErrorRegistry.getEntry(code);
|
|
178
176
|
if (registryEntry && (!registryEntry.condition || registryEntry.condition(error))) {
|
|
179
|
-
const exception = new ApplicationException(registryEntry.getMessage(
|
|
177
|
+
const exception = new ApplicationException(registryEntry.getMessage(t, error), registryEntry.code, serverMessage);
|
|
180
178
|
this.onRethrowError?.(error, exception);
|
|
181
179
|
throw exception;
|
|
182
180
|
}
|
|
183
181
|
}
|
|
184
182
|
const generalEntry = this.generalEntries.find((entry) => this.matchesEntry(error, entry, code));
|
|
185
|
-
const exception = new ApplicationException(generalEntry.getMessage(
|
|
183
|
+
const exception = new ApplicationException(generalEntry.getMessage(t, error), generalEntry.code, serverMessage);
|
|
186
184
|
this.onRethrowError?.(error, exception);
|
|
187
185
|
throw exception;
|
|
188
186
|
}
|
|
@@ -206,6 +204,5 @@ var ErrorHandler = class {
|
|
|
206
204
|
}
|
|
207
205
|
};
|
|
208
206
|
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
209
|
-
|
|
210
207
|
//#endregion
|
|
211
|
-
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 };
|
|
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 };
|