@povio/openapi-codegen-cli 2.0.8-rc.35 → 2.0.8-rc.36
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 +17 -0
- package/dist/{config-DqD9ExKp.d.mts → config-DTx4Ck6g.d.mts} +1 -1
- package/dist/{generate.runner-QejaDLjW.mjs → generate.runner-52viWKLA.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-C2niF2V7.mjs → generateCodeFromOpenAPIDoc-WP1lRhb0.mjs} +11 -5
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/{options-D3n-bZbj.d.mts → options-fyt0BYYE.d.mts} +1 -0
- package/dist/sh.mjs +8 -3
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,6 +92,7 @@ yarn openapi-codegen generate --config my-config.ts
|
|
|
92
92
|
--axiosRequestConfig Include Axios request config parameters in query hooks (default: false)
|
|
93
93
|
--infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
|
|
94
94
|
--mutationEffects Add mutation effects options to mutation hooks (default: true)
|
|
95
|
+
--mutationDefaultOnError Use OpenApiQueryConfig.onError as the default onError for mutation hooks (default: false)
|
|
95
96
|
--workspaceContext Comma-separated list of path/ACL params that generated hooks may resolve from OpenApiWorkspaceContext
|
|
96
97
|
--inlineEndpoints Inline endpoint implementations into generated query files (default: false)
|
|
97
98
|
--inlineEndpointsExcludeModules Comma-separated modules/tags to keep as separate API files while inlineEndpoints=true
|
|
@@ -194,6 +195,22 @@ const config: OpenAPICodegenConfig = {
|
|
|
194
195
|
export default config;
|
|
195
196
|
```
|
|
196
197
|
|
|
198
|
+
### Default mutation errors
|
|
199
|
+
|
|
200
|
+
Set `mutationDefaultOnError: true` in codegen config (or pass `--mutationDefaultOnError`) to let generated mutation hooks fall back to `OpenApiQueryConfig.Provider` when a mutation call does not define its own `onError`.
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
import { ErrorHandler, OpenApiQueryConfig } from "@povio/openapi-codegen-cli";
|
|
204
|
+
|
|
205
|
+
<OpenApiQueryConfig.Provider
|
|
206
|
+
onError={(error) => {
|
|
207
|
+
errorToast({ text: ErrorHandler.getErrorMessage(error) });
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
<App />
|
|
211
|
+
</OpenApiQueryConfig.Provider>;
|
|
212
|
+
```
|
|
213
|
+
|
|
197
214
|
### OpenApiWorkspaceContext (Path + ACL defaults)
|
|
198
215
|
|
|
199
216
|
Set `workspaceContext` to a list of param names in codegen config (or pass `--workspaceContext officeId,projectId`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { S as Profiler, i as writeGenerateFileData, m as DEFAULT_GENERATE_OPTIONS, o as deepMerge, r as removeStaleGeneratedFiles, t as generateCodeFromOpenAPIDoc } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
4
|
|
package/dist/{generateCodeFromOpenAPIDoc-C2niF2V7.mjs → generateCodeFromOpenAPIDoc-WP1lRhb0.mjs}
RENAMED
|
@@ -645,6 +645,7 @@ const DEFAULT_GENERATE_OPTIONS = {
|
|
|
645
645
|
queryTypesImportPath: PACKAGE_IMPORT_PATH,
|
|
646
646
|
axiosRequestConfig: false,
|
|
647
647
|
mutationEffects: true,
|
|
648
|
+
mutationDefaultOnError: false,
|
|
648
649
|
workspaceContext: [],
|
|
649
650
|
prefetchQueries: true,
|
|
650
651
|
infiniteQueries: false,
|
|
@@ -3468,6 +3469,7 @@ function generateConfigs(generateTypeParams) {
|
|
|
3468
3469
|
const hasMutation = endpoints.length > 0;
|
|
3469
3470
|
resolver.options.checkAcl && endpoints.some((e) => e.acl);
|
|
3470
3471
|
const hasMutationEffects = resolver.options.mutationEffects && hasMutation;
|
|
3472
|
+
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && hasMutation;
|
|
3471
3473
|
const hasWorkspaceContext = resolver.options.workspaceContext && endpoints.some((e) => resolver.options.workspaceContext);
|
|
3472
3474
|
const endpointsImports = getEndpointsImports({
|
|
3473
3475
|
tag,
|
|
@@ -3479,7 +3481,7 @@ function generateConfigs(generateTypeParams) {
|
|
|
3479
3481
|
from: "@tanstack/react-query"
|
|
3480
3482
|
};
|
|
3481
3483
|
const queryTypesImport = {
|
|
3482
|
-
bindings: ["OpenApiQueryConfig"],
|
|
3484
|
+
bindings: [...hasMutationDefaultOnError ? ["OpenApiQueryConfig"] : []],
|
|
3483
3485
|
typeBindings: [QUERY_OPTIONS_TYPES.mutation],
|
|
3484
3486
|
from: getQueryTypesImportPath(resolver.options)
|
|
3485
3487
|
};
|
|
@@ -3573,6 +3575,7 @@ function renderColumnsConfig(columnsConfig) {
|
|
|
3573
3575
|
function renderMutationContent(resolver, endpoint, tag) {
|
|
3574
3576
|
const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
|
|
3575
3577
|
const hasMutationEffects = resolver.options.mutationEffects;
|
|
3578
|
+
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError;
|
|
3576
3579
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
3577
3580
|
const endpointTag = getEndpointTag(endpoint, resolver.options);
|
|
3578
3581
|
const endpointParams = mapEndpointParamsToFunctionParams(resolver, endpoint, {
|
|
@@ -3585,7 +3588,7 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
3585
3588
|
const mutationVariablesType = endpoint.mediaUpload ? `{ ${endpointParamsStr}${endpointParamsStr ? "; " : ""}abortController?: AbortController; onUploadProgress?: (progress: { loaded: number; total: number }) => void }` : `{ ${endpointParamsStr} }`;
|
|
3586
3589
|
const lines = [];
|
|
3587
3590
|
lines.push(`(options?: AppMutationOptions<typeof ${endpointFunction}, ${mutationVariablesType}>${hasAxiosRequestConfig ? `, config?: AxiosRequestConfig` : ""}) => {`);
|
|
3588
|
-
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3591
|
+
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
3589
3592
|
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${endpointTag}>({ currentModule: ${QUERY_MODULE_ENUM}.${tag} });`);
|
|
3590
3593
|
lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
3591
3594
|
lines.push("");
|
|
@@ -3606,6 +3609,7 @@ function renderMutationContent(resolver, endpoint, tag) {
|
|
|
3606
3609
|
lines.push(" },");
|
|
3607
3610
|
}
|
|
3608
3611
|
lines.push(" ...options,");
|
|
3612
|
+
if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
3609
3613
|
lines.push(" });");
|
|
3610
3614
|
lines.push("}");
|
|
3611
3615
|
return lines.map((line) => " " + line).join("\n").trimStart();
|
|
@@ -3938,6 +3942,7 @@ function generateQueries(params) {
|
|
|
3938
3942
|
from: AXIOS_IMPORT.from
|
|
3939
3943
|
};
|
|
3940
3944
|
const { queryEndpoints, infiniteQueryEndpoints, mutationEndpoints, aclEndpoints } = endpointGroups;
|
|
3945
|
+
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError && mutationEndpoints.length > 0;
|
|
3941
3946
|
const queryImport = {
|
|
3942
3947
|
bindings: [
|
|
3943
3948
|
...resolver.options.prefetchQueries && queryEndpoints.length > 0 ? ["QueryClient"] : [],
|
|
@@ -3964,7 +3969,7 @@ function generateQueries(params) {
|
|
|
3964
3969
|
from: ACL_PACKAGE_IMPORT_PATH
|
|
3965
3970
|
};
|
|
3966
3971
|
const queryTypesImport = {
|
|
3967
|
-
bindings: [...
|
|
3972
|
+
bindings: [...hasMutationDefaultOnError ? ["OpenApiQueryConfig"] : []],
|
|
3968
3973
|
typeBindings: [
|
|
3969
3974
|
...queryEndpoints.length > 0 ? [QUERY_OPTIONS_TYPES.query] : [],
|
|
3970
3975
|
...resolver.options.infiniteQueries && infiniteQueryEndpoints.length > 0 ? [QUERY_OPTIONS_TYPES.infiniteQuery] : [],
|
|
@@ -4386,6 +4391,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4386
4391
|
function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
4387
4392
|
const hasAclCheck = resolver.options.checkAcl && endpoint.acl;
|
|
4388
4393
|
const hasMutationEffects = resolver.options.mutationEffects;
|
|
4394
|
+
const hasMutationDefaultOnError = resolver.options.mutationDefaultOnError;
|
|
4389
4395
|
const hasAxiosRequestConfig = resolver.options.axiosRequestConfig;
|
|
4390
4396
|
const tag = getEndpointTag(endpoint, resolver.options);
|
|
4391
4397
|
const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
|
|
@@ -4409,7 +4415,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4409
4415
|
tag
|
|
4410
4416
|
}));
|
|
4411
4417
|
lines.push(`export const ${getQueryName(endpoint, true)} = (options?: AppMutationOptions<typeof ${endpointFunction}, { ${mutationVariablesType} }>${hasMutationEffects ? ` & ${MUTATION_EFFECTS.optionsType}` : ""}${hasAxiosRequestConfig ? `, ${AXIOS_REQUEST_CONFIG_NAME}?: ${AXIOS_REQUEST_CONFIG_TYPE}` : ""}) => {`);
|
|
4412
|
-
lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4418
|
+
if (hasMutationDefaultOnError) lines.push(" const queryConfig = OpenApiQueryConfig.useConfig();");
|
|
4413
4419
|
if (hasAclCheck) lines.push(` const { checkAcl } = ${ACL_CHECK_HOOK}();`);
|
|
4414
4420
|
if (Object.keys(workspaceParamReplacements).length > 0) lines.push(" const workspaceContext = OpenApiWorkspaceContext.useContext();");
|
|
4415
4421
|
if (hasMutationEffects) lines.push(` const { runMutationEffects } = useMutationEffects<typeof ${QUERY_MODULE_ENUM}.${tag}>({ currentModule: ${QUERIES_MODULE_NAME} });`);
|
|
@@ -4450,7 +4456,7 @@ function renderMutation({ resolver, endpoint, inlineEndpoints, precomputed }) {
|
|
|
4450
4456
|
if (hasMutationFnBody) lines.push(" },");
|
|
4451
4457
|
else lines.push(",");
|
|
4452
4458
|
lines.push(" ...options,");
|
|
4453
|
-
lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
4459
|
+
if (hasMutationDefaultOnError) lines.push(" onError: options?.onError ?? queryConfig.onError,");
|
|
4454
4460
|
if (hasMutationEffects) {
|
|
4455
4461
|
lines.push(" onSuccess: async (resData, variables, onMutateResult, context) => {");
|
|
4456
4462
|
if (updateQueryEndpoints.length > 0) {
|
package/dist/generator.d.mts
CHANGED
package/dist/generator.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { a as getDataFromOpenAPIDoc, b as invalidVariableNameCharactersToCamel, c as isQuery, f as getTagImportPath, g as GenerateType, h as getNamespaceName, l as getSchemaTsMetaType, m as DEFAULT_GENERATE_OPTIONS, p as getQueryName, s as isMutation, t as generateCodeFromOpenAPIDoc, u as getTsTypeBase, v as isMediaTypeAllowed, x as formatTag, y as isParamMediaTypeAllowed } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/core/getMetadataFromOpenAPIDoc.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as GeneralErrorCodes, i as ErrorHandlerOptions, n as ErrorEntry, o as SharedErrorHandler, r as ErrorHandler, t as ApplicationException } from "./error-handling-CXeVTk1T.mjs";
|
|
2
|
-
import "./options-
|
|
3
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
2
|
+
import "./options-fyt0BYYE.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-DTx4Ck6g.mjs";
|
|
4
4
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import "i18next";
|
package/dist/sh.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-
|
|
3
|
-
import { n as resolveConfig, t as runGenerate } from "./generate.runner-
|
|
2
|
+
import { C as VALIDATION_ERROR_TYPE_TITLE, S as Profiler, _ as groupByType, a as getDataFromOpenAPIDoc, d as getTagFileName, g as GenerateType, n as getOutputFileName } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-52viWKLA.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import yargs from "yargs";
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
@@ -39,7 +39,7 @@ function logBanner(message) {
|
|
|
39
39
|
* Fetch the version from package.json
|
|
40
40
|
*/
|
|
41
41
|
function getVersion() {
|
|
42
|
-
return "2.0.8-rc.
|
|
42
|
+
return "2.0.8-rc.36";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
|
@@ -320,6 +320,7 @@ var GenerateOptions = class {
|
|
|
320
320
|
replaceOptionalWithNullish;
|
|
321
321
|
infiniteQueries;
|
|
322
322
|
mutationEffects;
|
|
323
|
+
mutationDefaultOnError;
|
|
323
324
|
workspaceContext;
|
|
324
325
|
parseRequestParams;
|
|
325
326
|
inlineEndpoints;
|
|
@@ -389,6 +390,10 @@ __decorate([YargOption({
|
|
|
389
390
|
envAlias: "mutationEffects",
|
|
390
391
|
type: "boolean"
|
|
391
392
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationEffects", void 0);
|
|
393
|
+
__decorate([YargOption({
|
|
394
|
+
envAlias: "mutationDefaultOnError",
|
|
395
|
+
type: "boolean"
|
|
396
|
+
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationDefaultOnError", void 0);
|
|
392
397
|
__decorate([YargOption({ envAlias: "workspaceContext" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "workspaceContext", void 0);
|
|
393
398
|
__decorate([YargOption({
|
|
394
399
|
envAlias: "parseRequestParams",
|
package/dist/vite.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as GenerateFileFormatter } from "./options-
|
|
2
|
-
import { t as OpenAPICodegenConfig } from "./config-
|
|
1
|
+
import { r as GenerateFileFormatter } from "./options-fyt0BYYE.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-DTx4Ck6g.mjs";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.d.ts
|
package/dist/vite.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
2
|
-
import { t as runGenerate } from "./generate.runner-
|
|
1
|
+
import { S as Profiler } from "./generateCodeFromOpenAPIDoc-WP1lRhb0.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-52viWKLA.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.ts
|