@povio/openapi-codegen-cli 2.0.8-rc.33 → 2.0.8-rc.35
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 +4 -4
- package/dist/{config-KffSntOs.d.mts → config-DqD9ExKp.d.mts} +1 -1
- package/dist/{generate.runner-DUGWfT_G.mjs → generate.runner-QejaDLjW.mjs} +5 -3
- package/dist/{generateCodeFromOpenAPIDoc-D_spaAd2.mjs → generateCodeFromOpenAPIDoc-C2niF2V7.mjs} +17 -6
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/{options-D9TC-n26.d.mts → options-D3n-bZbj.d.mts} +1 -1
- package/dist/sh.mjs +4 -7
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,7 +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
|
-
--workspaceContext
|
|
95
|
+
--workspaceContext Comma-separated list of path/ACL params that generated hooks may resolve from OpenApiWorkspaceContext
|
|
96
96
|
--inlineEndpoints Inline endpoint implementations into generated query files (default: false)
|
|
97
97
|
--inlineEndpointsExcludeModules Comma-separated modules/tags to keep as separate API files while inlineEndpoints=true
|
|
98
98
|
--modelsOnly Generate only model files (default: false)
|
|
@@ -196,18 +196,18 @@ export default config;
|
|
|
196
196
|
|
|
197
197
|
### OpenApiWorkspaceContext (Path + ACL defaults)
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
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.
|
|
200
200
|
|
|
201
201
|
```tsx
|
|
202
202
|
import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli";
|
|
203
|
-
// openapi-codegen.config.ts -> { workspaceContext:
|
|
203
|
+
// openapi-codegen.config.ts -> { workspaceContext: ["officeId", "projectId"] }
|
|
204
204
|
|
|
205
205
|
<OpenApiWorkspaceContext.Provider values={{ officeId: "office_123" }}>
|
|
206
206
|
<MyWorkspacePages />
|
|
207
207
|
</OpenApiWorkspaceContext.Provider>;
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
-
Generated query/mutation hooks can then omit matching path/ACL params and resolve them from `OpenApiWorkspaceContext`.
|
|
210
|
+
Generated query/mutation hooks can then omit only those matching path/ACL params and resolve them from `OpenApiWorkspaceContext`. Params not listed in `workspaceContext` remain explicit and required.
|
|
211
211
|
|
|
212
212
|
### Generation Modes
|
|
213
213
|
|
|
@@ -1,16 +1,18 @@
|
|
|
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-C2niF2V7.mjs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
4
4
|
|
|
5
5
|
//#region src/generators/core/resolveConfig.ts
|
|
6
|
-
function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, ...options } }) {
|
|
6
|
+
function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
|
|
7
7
|
const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
|
|
8
8
|
...options,
|
|
9
9
|
includeTags: includeTags?.split(","),
|
|
10
10
|
excludeTags: excludeTags?.split(","),
|
|
11
|
-
inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(",")
|
|
11
|
+
inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
|
|
12
|
+
workspaceContext: workspaceContext?.split(",")
|
|
12
13
|
});
|
|
13
14
|
resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
|
|
15
|
+
resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
|
|
14
16
|
return resolvedConfig;
|
|
15
17
|
}
|
|
16
18
|
|
package/dist/{generateCodeFromOpenAPIDoc-D_spaAd2.mjs → generateCodeFromOpenAPIDoc-C2niF2V7.mjs}
RENAMED
|
@@ -645,7 +645,7 @@ const DEFAULT_GENERATE_OPTIONS = {
|
|
|
645
645
|
queryTypesImportPath: PACKAGE_IMPORT_PATH,
|
|
646
646
|
axiosRequestConfig: false,
|
|
647
647
|
mutationEffects: true,
|
|
648
|
-
workspaceContext:
|
|
648
|
+
workspaceContext: [],
|
|
649
649
|
prefetchQueries: true,
|
|
650
650
|
infiniteQueries: false,
|
|
651
651
|
infiniteQueryParamNames: { page: "page" },
|
|
@@ -1248,6 +1248,7 @@ const hasEndpointConfig = (endpoint, resolver) => {
|
|
|
1248
1248
|
};
|
|
1249
1249
|
const getEndpointPath = (endpoint) => endpoint.path.replace(/:([a-zA-Z0-9_]+)/g, "${$1}");
|
|
1250
1250
|
function mapEndpointParamsToFunctionParams(resolver, endpoint, options) {
|
|
1251
|
+
const optionalPathParams = options?.optionalPathParams ? new Set(options.optionalPathParams) : void 0;
|
|
1251
1252
|
const params = endpoint.parameters.map((param) => {
|
|
1252
1253
|
let type = "string";
|
|
1253
1254
|
if (isNamedZodSchema(param.zodSchema)) type = getImportedZodSchemaInferedTypeName(resolver, param.zodSchema, void 0, options?.modelNamespaceTag);
|
|
@@ -1286,7 +1287,7 @@ function mapEndpointParamsToFunctionParams(resolver, endpoint, options) {
|
|
|
1286
1287
|
}).filter((param) => (!options?.excludeBodyParam || param.name !== BODY_PARAMETER_NAME) && (!options?.excludePageParam || param.name !== resolver.options.infiniteQueryParamNames.page) && (!options?.includeOnlyRequiredParams || param.required)).map((param) => ({
|
|
1287
1288
|
...param,
|
|
1288
1289
|
name: options?.replacePageParam && param.name === resolver.options.infiniteQueryParamNames.page ? "pageParam" : param.name,
|
|
1289
|
-
required:
|
|
1290
|
+
required: param.paramType === "Path" && optionalPathParams?.has(param.name) ? false : param.required && (param.paramType === "Path" || !options?.pathParamsRequiredOnly)
|
|
1290
1291
|
}));
|
|
1291
1292
|
}
|
|
1292
1293
|
function getEndpointConfig(endpoint) {
|
|
@@ -4114,13 +4115,16 @@ function getEndpointParamMapping(resolver, endpoint, options) {
|
|
|
4114
4115
|
endpointCache = /* @__PURE__ */ new Map();
|
|
4115
4116
|
resolverCache.set(endpoint, endpointCache);
|
|
4116
4117
|
}
|
|
4117
|
-
const key = JSON.stringify(Object.entries(options ?? {}).sort(([left], [right]) => left.localeCompare(right)).map(([optionName, optionValue]) => [optionName,
|
|
4118
|
+
const key = JSON.stringify(Object.entries(options ?? {}).sort(([left], [right]) => left.localeCompare(right)).map(([optionName, optionValue]) => [optionName, optionValue]));
|
|
4118
4119
|
const cached = endpointCache.get(key);
|
|
4119
4120
|
if (cached) return cached;
|
|
4120
4121
|
const computed = mapEndpointParamsToFunctionParams(resolver, endpoint, options);
|
|
4121
4122
|
endpointCache.set(key, computed);
|
|
4122
4123
|
return computed;
|
|
4123
4124
|
}
|
|
4125
|
+
function getWorkspaceContextAllowList(workspaceContext) {
|
|
4126
|
+
return new Set(workspaceContext);
|
|
4127
|
+
}
|
|
4124
4128
|
function renderImport(importData) {
|
|
4125
4129
|
const namedImports = [...importData.bindings, ...(importData.typeBindings ?? []).map((binding) => importData.typeOnly ? binding : `type ${binding}`)];
|
|
4126
4130
|
const names = [...importData.defaultImport ? [importData.defaultImport] : [], ...namedImports.length > 0 ? [`{ ${namedImports.join(", ")} }`] : []].join(", ");
|
|
@@ -4132,6 +4136,12 @@ function renderEndpointParams(resolver, endpoint, options) {
|
|
|
4132
4136
|
function renderEndpointArgs(resolver, endpoint, options, replacements) {
|
|
4133
4137
|
return getEndpointParamMapping(resolver, endpoint, options).map((param) => replacements?.[param.name] ?? param.name).join(", ");
|
|
4134
4138
|
}
|
|
4139
|
+
function renderEndpointObjectArgs(resolver, endpoint, options, replacements) {
|
|
4140
|
+
return getEndpointParamMapping(resolver, endpoint, options).map((param) => {
|
|
4141
|
+
const replacement = replacements?.[param.name];
|
|
4142
|
+
return replacement && replacement !== param.name ? `${param.name}: ${replacement}` : param.name;
|
|
4143
|
+
}).join(", ");
|
|
4144
|
+
}
|
|
4135
4145
|
function renderEndpointParamDescription(endpointParam) {
|
|
4136
4146
|
const strs = [`${endpointParam.paramType} parameter`];
|
|
4137
4147
|
const description = endpointParam.parameterObject?.description || endpointParam.bodyObject?.description;
|
|
@@ -4151,11 +4161,12 @@ function renderEndpointParamDescription(endpointParam) {
|
|
|
4151
4161
|
return strs.join(". ");
|
|
4152
4162
|
}
|
|
4153
4163
|
function getWorkspaceParamNames(resolver, endpoint) {
|
|
4164
|
+
const allowList = getWorkspaceContextAllowList(resolver.options.workspaceContext);
|
|
4154
4165
|
const endpointParams = getEndpointParamMapping(resolver, endpoint, {});
|
|
4155
4166
|
const endpointParamNames = new Set(endpointParams.map((param) => param.name));
|
|
4156
4167
|
const workspaceParamNames = endpointParams.filter((param) => param.paramType === "Path").map((param) => param.name);
|
|
4157
4168
|
const aclParamNames = (getAbilityConditionsTypes(endpoint) ?? []).map((condition) => invalidVariableNameCharactersToCamel(condition.name)).filter((name) => endpointParamNames.has(name));
|
|
4158
|
-
return getUniqueArray([...workspaceParamNames, ...aclParamNames]);
|
|
4169
|
+
return getUniqueArray([...workspaceParamNames, ...aclParamNames]).filter((name) => allowList.has(name));
|
|
4159
4170
|
}
|
|
4160
4171
|
function getWorkspaceParamReplacements(resolver, endpoint) {
|
|
4161
4172
|
return Object.fromEntries(getWorkspaceParamNames(resolver, endpoint).map((name) => [name, `${name}FromWorkspace`]));
|
|
@@ -4337,7 +4348,7 @@ function renderQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4337
4348
|
const tag = getEndpointTag(endpoint, resolver.options);
|
|
4338
4349
|
const workspaceParamReplacements = resolver.options.workspaceContext ? getWorkspaceParamReplacements(resolver, endpoint) : {};
|
|
4339
4350
|
const endpointArgs = renderEndpointArgs(resolver, endpoint, {});
|
|
4340
|
-
const resolvedEndpointArgs =
|
|
4351
|
+
const resolvedEndpointArgs = renderEndpointObjectArgs(resolver, endpoint, {}, workspaceParamReplacements);
|
|
4341
4352
|
const endpointParams = renderEndpointParams(resolver, endpoint, {
|
|
4342
4353
|
optionalPathParams: resolver.options.workspaceContext,
|
|
4343
4354
|
modelNamespaceTag: tag
|
|
@@ -4503,7 +4514,7 @@ function renderInfiniteQuery({ resolver, endpoint, inlineEndpoints }) {
|
|
|
4503
4514
|
modelNamespaceTag: tag
|
|
4504
4515
|
});
|
|
4505
4516
|
const endpointArgsWithoutPage = renderEndpointArgs(resolver, endpoint, { excludePageParam: true });
|
|
4506
|
-
const resolvedEndpointArgsWithoutPage =
|
|
4517
|
+
const resolvedEndpointArgsWithoutPage = renderEndpointObjectArgs(resolver, endpoint, { excludePageParam: true }, workspaceParamReplacements);
|
|
4507
4518
|
const queryOptionsName = getInfiniteQueryOptionsName(endpoint);
|
|
4508
4519
|
const queryOptionsArgs = `${resolvedEndpointArgsWithoutPage ? `{ ${resolvedEndpointArgsWithoutPage} }` : ""}${hasAxiosRequestConfig ? `${resolvedEndpointArgsWithoutPage ? ", " : ""}${AXIOS_REQUEST_CONFIG_NAME}` : ""}`;
|
|
4509
4520
|
const hasQueryFnOverride = hasAclCheck;
|
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-C2niF2V7.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-D3n-bZbj.mjs";
|
|
3
|
+
import { t as OpenAPICodegenConfig } from "./config-DqD9ExKp.mjs";
|
|
4
4
|
import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import "i18next";
|
|
@@ -39,7 +39,7 @@ interface QueriesGenerateOptions {
|
|
|
39
39
|
queryTypesImportPath: string;
|
|
40
40
|
axiosRequestConfig?: boolean;
|
|
41
41
|
mutationEffects?: boolean;
|
|
42
|
-
workspaceContext?:
|
|
42
|
+
workspaceContext?: string[];
|
|
43
43
|
prefetchQueries?: boolean;
|
|
44
44
|
}
|
|
45
45
|
interface InfiniteQueriesGenerateOptions {
|
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-C2niF2V7.mjs";
|
|
3
|
+
import { n as resolveConfig, t as runGenerate } from "./generate.runner-QejaDLjW.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.35";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
//#endregion
|
|
@@ -389,10 +389,7 @@ __decorate([YargOption({
|
|
|
389
389
|
envAlias: "mutationEffects",
|
|
390
390
|
type: "boolean"
|
|
391
391
|
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "mutationEffects", void 0);
|
|
392
|
-
__decorate([YargOption({
|
|
393
|
-
envAlias: "workspaceContext",
|
|
394
|
-
type: "boolean"
|
|
395
|
-
}), __decorateMetadata("design:type", Boolean)], GenerateOptions.prototype, "workspaceContext", void 0);
|
|
392
|
+
__decorate([YargOption({ envAlias: "workspaceContext" }), __decorateMetadata("design:type", String)], GenerateOptions.prototype, "workspaceContext", void 0);
|
|
396
393
|
__decorate([YargOption({
|
|
397
394
|
envAlias: "parseRequestParams",
|
|
398
395
|
type: "boolean"
|
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-D3n-bZbj.mjs";
|
|
2
|
+
import { t as OpenAPICodegenConfig } from "./config-DqD9ExKp.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-C2niF2V7.mjs";
|
|
2
|
+
import { t as runGenerate } from "./generate.runner-QejaDLjW.mjs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
5
|
//#region src/vite/openapi-codegen.plugin.ts
|